AnotherUser
AnotherUser

Reputation: 1353

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?

Upvotes: 0

Views: 122

Answers (1)

Servy
Servy

Reputation: 203820

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.

Upvotes: 2

Related Questions