简体   繁体   中英

Raising an event

I have a form with two RichTextBoxs on them, I want to raise an event in one to trigger an event on the form which updates something in the other rtb.

Where must I define the EventArgs extended class? What is and where must my delegate be? Is this the function that is called from the event being raised? Do these three classes (rtb1, rtb2, form1) need to be in the same namespace?

Rather than defining your own delegate you can almost always use the generic EventArgs class, or the Action class as the delegate for your events. When using one of these you won't need to define any delegate at all, they are already defined by the library.

The delegate is not the function being called, it merely defines the signature of all methods that are called by the event.

The three classes do not need to be in the same namespace, no. In fact, as a general rule, there are almost no situations (none that I can think of anyway) which would force you to have classes in the same namespace for them to do something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM