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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UlJK?=

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

    Hello,
    I would like to add the Paint handler to the form. How to do it?
    Thanks in advance.
  • Peter Duniho

    #2
    Re: How to add an event handler to a form in VS 2005?

    On Sun, 28 Sep 2008 16:43:00 -0700, RRJ <RRJ@discussion s.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

    Comment

    • =?Utf-8?B?UlJK?=

      #3
      Re: How to add an event handler to a form in VS 2005?

      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 <RRJ@discussion s.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
      >

      Comment

      Working...