.net - c# event handling between two forms -


I have two forms and I am trying to capture the event that occurs in frmEventReceive.cs from frmEventGenerate.cs I am

In this example I can get the event from frmEventGenerate.cs but not sure how can I capture it in frmEventReceive.cs? FrmEventReceive.cs is my startup form which creates frmEventGenerate.cs.

Can someone tell me in the right direction, I think I'm stupid!

thanks

frmEventGenerate.cs:

  using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; Namespace Event {Public Representative Zero LinkToEventHandler (); Public partial class frmEventGenerate: form {public static event LinkToEventHandler Evt; Public frmEventGenerate () {InitializeComponent (); Evt + = new LinkToEventHandler (ReceiveEvent); SendEvent (); } Public static zero SendEvent () {if (Evt! = Null) {Evt (); }} Public Zero Recipient () {System.Console.WriteLine ("Received Event - It Works OK"); }}}  

frmEventReceive.cs:

 using the  system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; Namespace event {public partial square frmEventReceive: form {public frmEventReceive () {InitializeComponent (); FrmEventGenerate frmGen = new frmEventGenerate (); } Public Zero Recipient () {System.Console.WriteLine ("I want to be able to get here!"); }}}}  

In your constructor, frmEventGenerate After promptly:

  frmGen.Evt + = ReceiveEvent;  

You do not need new LinkEventHandler (...) - as a C # 2, an method group conversion is available Which you can use to convert from a method group (name of a method) to a representative type.

EDIT: I did not see that your event was stable, it shows that you really should use it:

  frmEventGenerate.Evt + = ReceiveEvent;  

... and you do not need the frmGen variable.

However, I will strongly disappoint you with this - why do you want to be stable in the first place? (I also tell you more of your type of names more wisely - for example, something like "Event Generator" would be better, for example, to ignore the conference that type in the Pascal case should be a name, this code would get confused. Is.)


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -