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

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

        当另一个类的事件被触发时通知

        Notify when event from another class is triggered(当另一个类的事件被触发时通知)

        <legend id='fnLgY'><style id='fnLgY'><dir id='fnLgY'><q id='fnLgY'></q></dir></style></legend>
          <tbody id='fnLgY'></tbody>

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

            <tfoot id='fnLgY'></tfoot>
              <bdo id='fnLgY'></bdo><ul id='fnLgY'></ul>
              • <i id='fnLgY'><tr id='fnLgY'><dt id='fnLgY'><q id='fnLgY'><span id='fnLgY'><b id='fnLgY'><form id='fnLgY'><ins id='fnLgY'></ins><ul id='fnLgY'></ul><sub id='fnLgY'></sub></form><legend id='fnLgY'></legend><bdo id='fnLgY'><pre id='fnLgY'><center id='fnLgY'></center></pre></bdo></b><th id='fnLgY'></th></span></q></dt></tr></i><div id='fnLgY'><tfoot id='fnLgY'></tfoot><dl id='fnLgY'><fieldset id='fnLgY'></fieldset></dl></div>
                  本文介绍了当另一个类的事件被触发时通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have

                  class A
                  {
                      B b;
                  
                      //call this Method when b.Button_click or b.someMethod is launched
                      private void MyMethod()
                      {            
                      }
                  
                      ??
                  }
                  
                  Class B
                  {
                      //here i.e. a button is pressed and in Class A 
                      //i want to call also MyMethod() in Class A after the button is pressed 
                      private void Button_Click(object o, EventArgs s)
                      {
                           SomeMethod();
                      }
                  
                      public void SomeMethod()
                      {           
                      }
                  
                      ??
                  }
                  

                  Class A has a instance of Class B.

                  How can this be done?

                  解决方案

                  You'll need to declare a public event on class 'B' - and have class 'A' subscribe to it:

                  Something like this:

                  class B
                  {
                      //A public event for listeners to subscribe to
                      public event EventHandler SomethingHappened;
                  
                      private void Button_Click(object o, EventArgs s)
                      {
                          //Fire the event - notifying all subscribers
                          if(SomethingHappened != null)
                              SomethingHappened(this, null);
                      }
                  ....
                  
                  class A
                  {
                      //Where B is used - subscribe to it's public event
                      public A()
                      {
                          B objectToSubscribeTo = new B();
                          objectToSubscribeTo.SomethingHappened += HandleSomethingHappening;
                      }
                  
                      public void HandleSomethingHappening(object sender, EventArgs e)
                      {
                          //Do something here
                      }
                  
                  ....
                  

                  这篇关于当另一个类的事件被触发时通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                  <i id='y5cKU'><tr id='y5cKU'><dt id='y5cKU'><q id='y5cKU'><span id='y5cKU'><b id='y5cKU'><form id='y5cKU'><ins id='y5cKU'></ins><ul id='y5cKU'></ul><sub id='y5cKU'></sub></form><legend id='y5cKU'></legend><bdo id='y5cKU'><pre id='y5cKU'><center id='y5cKU'></center></pre></bdo></b><th id='y5cKU'></th></span></q></dt></tr></i><div id='y5cKU'><tfoot id='y5cKU'></tfoot><dl id='y5cKU'><fieldset id='y5cKU'></fieldset></dl></div>
                  <legend id='y5cKU'><style id='y5cKU'><dir id='y5cKU'><q id='y5cKU'></q></dir></style></legend>

                  • <bdo id='y5cKU'></bdo><ul id='y5cKU'></ul>

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

                          <tbody id='y5cKU'></tbody>
                          <tfoot id='y5cKU'></tfoot>