<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 用户控件自定义事件

        时间:2023-09-15
          <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 用户控件自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:通过 EventHandler 传回返回值 下一篇:动作&lt;对象,EventArgs&gt;无法转换为 EventHandler?

                  相关文章

                  <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>

                  2. <legend id='5b045'><style id='5b045'><dir id='5b045'><q id='5b045'></q></dir></style></legend>