<small id='crkRj'></small><noframes id='crkRj'>

  • <i id='crkRj'><tr id='crkRj'><dt id='crkRj'><q id='crkRj'><span id='crkRj'><b id='crkRj'><form id='crkRj'><ins id='crkRj'></ins><ul id='crkRj'></ul><sub id='crkRj'></sub></form><legend id='crkRj'></legend><bdo id='crkRj'><pre id='crkRj'><center id='crkRj'></center></pre></bdo></b><th id='crkRj'></th></span></q></dt></tr></i><div id='crkRj'><tfoot id='crkRj'></tfoot><dl id='crkRj'><fieldset id='crkRj'></fieldset></dl></div>
    <legend id='crkRj'><style id='crkRj'><dir id='crkRj'><q id='crkRj'></q></dir></style></legend>

      <bdo id='crkRj'></bdo><ul id='crkRj'></ul>

        <tfoot id='crkRj'></tfoot>
      1. Winforms 用户控件自定义事件

        Winforms user controls custom events(Winforms 用户控件自定义事件)
          <bdo id='W0vmp'></bdo><ul id='W0vmp'></ul>

              <legend id='W0vmp'><style id='W0vmp'><dir id='W0vmp'><q id='W0vmp'></q></dir></style></legend>

              <tfoot id='W0vmp'></tfoot>
              • <small id='W0vmp'></small><noframes id='W0vmp'>

                  <i id='W0vmp'><tr id='W0vmp'><dt id='W0vmp'><q id='W0vmp'><span id='W0vmp'><b id='W0vmp'><form id='W0vmp'><ins id='W0vmp'></ins><ul id='W0vmp'></ul><sub id='W0vmp'></sub></form><legend id='W0vmp'></legend><bdo id='W0vmp'><pre id='W0vmp'><center id='W0vmp'></center></pre></bdo></b><th id='W0vmp'></th></span></q></dt></tr></i><div id='W0vmp'><tfoot id='W0vmp'></tfoot><dl id='W0vmp'><fieldset id='W0vmp'></fieldset></dl></div>

                    <tbody id='W0vmp'></tbody>
                  本文介绍了Winforms 用户控件自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法给用户控件自定义事件,并在用户控件内的事件上调用事件.(我不确定调用是否是正确的术语)

                  Is there a way to give a User Control custom events, and invoke the event on a event within the user control. (I'm not sure if invoke is the correct term)

                  public partial class Sample: UserControl
                  {
                      public Sample()
                      {
                          InitializeComponent();
                      }
                  
                  
                      private void TextBox_Validated(object sender, EventArgs e)
                      {
                          // invoke UserControl event here
                      }
                  }
                  

                  主窗体:

                  public partial class MainForm : Form
                  {
                      private Sample sampleUserControl = new Sample();
                  
                      public MainForm()
                      {
                          this.InitializeComponent();
                          sampleUserControl.Click += new EventHandler(this.CustomEvent_Handler);
                      }
                      private void CustomEvent_Handler(object sender, EventArgs e)
                      {
                          // do stuff
                      }
                  }
                  

                  推荐答案

                  除了 Steve 发布的示例之外,还有一些可用的语法可以简单地传递事件.类似于创建属性:

                  Aside from the example that Steve posted, there is also syntax available which can simply pass the event through. It is similar to creating a property:

                  class MyUserControl : UserControl
                  {
                     public event EventHandler TextBoxValidated
                     {
                        add { textBox1.Validated += value; }
                        remove { textBox1.Validated -= value; }
                     }
                  }
                  

                  这篇关于Winforms 用户控件自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  IBM.Data.DB2.Core connection problems(IBM.Data.DB2.Core 连接问题)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  Datetime field overflow with IBM Data Server Client v9.7fp5(IBM Data Server Client v9.7fp5 的日期时间字段溢出)
                  Using entity Framework with .NET Core and DB2(将实体框架与 .NET Core 和 DB2 结合使用)
                  <tfoot id='5b045'></tfoot>
                  1. <i id='5b045'><tr id='5b045'><dt id='5b045'><q id='5b045'><span id='5b045'><b id='5b045'><form id='5b045'><ins id='5b045'></ins><ul id='5b045'></ul><sub id='5b045'></sub></form><legend id='5b045'></legend><bdo id='5b045'><pre id='5b045'><center id='5b045'></center></pre></bdo></b><th id='5b045'></th></span></q></dt></tr></i><div id='5b045'><tfoot id='5b045'></tfoot><dl id='5b045'><fieldset id='5b045'></fieldset></dl></div>

                    <small id='5b045'></small><noframes id='5b045'>

                      <bdo id='5b045'></bdo><ul id='5b045'></ul>

                      • <legend id='5b045'><style id='5b045'><dir id='5b045'><q id='5b045'></q></dir></style></legend>
                              <tbody id='5b045'></tbody>