By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

How to add an event handler to a form in VS 2005?

P: n/a
Hello,
I would like to add the Paint handler to the form. How to do it?
Thanks in advance.
Sep 28 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sun, 28 Sep 2008 16:43:00 -0700, RRJ <RR*@discussions.microsoft.com>
wrote:
Hello,
I would like to add the Paint handler to the form. How to do it?
What do you mean? Do you mean you have an event handler that you want
subscribed to a form's Paint event? Or do you mean you have a form's
Paint event and you want to write an event handler for it?

In either case, there are ways to do it using the IDE and doing it
manually.

Subscribe an event handler:

-- Using the IDE, choose the "Events" list in the form's Properties
window, find the Paint event, click in the edit area and a drop-down
showing all eligible handlers in the container will be shown (in this
case, that's likely to just be the form)

-- Doing it manually, simply use the C# event add syntax. For
example, where the handler method's name is "MyPaintHandler":

Form form = ...; // your initialization goes here

form.Paint += MyPaintHandler;

Write an event handler:

-- Using the IDE, as above for subscribing a handler, but double-click
in the edit area instead. A new handler will be inserted in the relevant
container class, to which you can add whatever code you want.

-- Doing it manually, just write the event handler method, ensuring
that the signature for the method is correct. For the Paint event, you
need a method that looks like this:

void MyPaintHandler(object sender, PaintEventArgs e)
{
}

Pete
Sep 29 '08 #2

P: n/a
Thanks Pete.

I could add the event manually, but didn't know how to do it from IDE. Your
solution (properties->events) helped solve it.

Thanks again.

"Peter Duniho" wrote:
On Sun, 28 Sep 2008 16:43:00 -0700, RRJ <RR*@discussions.microsoft.com>
wrote:
Hello,
I would like to add the Paint handler to the form. How to do it?

What do you mean? Do you mean you have an event handler that you want
subscribed to a form's Paint event? Or do you mean you have a form's
Paint event and you want to write an event handler for it?

In either case, there are ways to do it using the IDE and doing it
manually.

Subscribe an event handler:

-- Using the IDE, choose the "Events" list in the form's Properties
window, find the Paint event, click in the edit area and a drop-down
showing all eligible handlers in the container will be shown (in this
case, that's likely to just be the form)

-- Doing it manually, simply use the C# event add syntax. For
example, where the handler method's name is "MyPaintHandler":

Form form = ...; // your initialization goes here

form.Paint += MyPaintHandler;

Write an event handler:

-- Using the IDE, as above for subscribing a handler, but double-click
in the edit area instead. A new handler will be inserted in the relevant
container class, to which you can add whatever code you want.

-- Doing it manually, just write the event handler method, ensuring
that the signature for the method is correct. For the Paint event, you
need a method that looks like this:

void MyPaintHandler(object sender, PaintEventArgs e)
{
}

Pete
Sep 29 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.