Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Raise my Custom Event Handler

How to Raise my Custom Event Handler

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hdv212
    wrote on last edited by
    #1

    Hi i maked a custom event as 'MouseMoveExEventArgs' that inherited from MouseEventArgs to add some more property and info as follow : namespace CustomEventHandler { public delegate void MouseMoveExEvent(object sender, MouseMoveExEventArgs e); public class MouseMoveExEventArgs : System.Windows.Forms.MouseEventArgs { Point m_mapScrollPos; public MouseMoveExEventArgs(Point mapScrollPosition) : base(System.Windows.Forms.MouseButtons.Left,1,mapScrollPosition.X,mapScrollPosition.Y,0) { this.m_mapScrollPos = mapScrollPosition; } public Point MapScrollPosition { get { return this.m_mapScrollPos; } } } } and in my custom user control, write this code : public event MouseMoveExEvent MouseMoveEx; . . . protected virtual void OnMouseMoveEx(MouseMoveExEventArgs e) { if (MouseMoveEx != null) { MouseMoveEx(this, e); } } but i don't know how to raise this event, when mouse move on my control (like MouseMove event), for this work, i call OnMouseMoveEx event handler in OnMouseMove event handler as follow : protected override void OnMouseMove(MouseEventArgs e) { Point p = new Point(e.X, e.Y); OnMouseMoveEx(new MouseMoveExEventArgs(p)); } my purpose is that replace orginal MouseEventArgs class with MouseMoveExEventArgs event handler in MouseMove event and raise it when Mousemove event fire. thanks

    A 1 Reply Last reply
    0
    • H hdv212

      Hi i maked a custom event as 'MouseMoveExEventArgs' that inherited from MouseEventArgs to add some more property and info as follow : namespace CustomEventHandler { public delegate void MouseMoveExEvent(object sender, MouseMoveExEventArgs e); public class MouseMoveExEventArgs : System.Windows.Forms.MouseEventArgs { Point m_mapScrollPos; public MouseMoveExEventArgs(Point mapScrollPosition) : base(System.Windows.Forms.MouseButtons.Left,1,mapScrollPosition.X,mapScrollPosition.Y,0) { this.m_mapScrollPos = mapScrollPosition; } public Point MapScrollPosition { get { return this.m_mapScrollPos; } } } } and in my custom user control, write this code : public event MouseMoveExEvent MouseMoveEx; . . . protected virtual void OnMouseMoveEx(MouseMoveExEventArgs e) { if (MouseMoveEx != null) { MouseMoveEx(this, e); } } but i don't know how to raise this event, when mouse move on my control (like MouseMove event), for this work, i call OnMouseMoveEx event handler in OnMouseMove event handler as follow : protected override void OnMouseMove(MouseEventArgs e) { Point p = new Point(e.X, e.Y); OnMouseMoveEx(new MouseMoveExEventArgs(p)); } my purpose is that replace orginal MouseEventArgs class with MouseMoveExEventArgs event handler in MouseMove event and raise it when Mousemove event fire. thanks

      A Offline
      A Offline
      amargujrathi2006
      wrote on last edited by
      #2

      Hi According to my knowledge when you want use any event of custom control,you need to assign local handler to that event ; eg. customcontrol1.MouseMoveEx+=OnMouseMoveEx; where OnMouseMoveEx and customcontrol1 are both in one class. I think, you will get how to do it. Regards, Amar

      H 1 Reply Last reply
      0
      • A amargujrathi2006

        Hi According to my knowledge when you want use any event of custom control,you need to assign local handler to that event ; eg. customcontrol1.MouseMoveEx+=OnMouseMoveEx; where OnMouseMoveEx and customcontrol1 are both in one class. I think, you will get how to do it. Regards, Amar

        H Offline
        H Offline
        hdv212
        wrote on last edited by
        #3

        thanks when in designer mode, double click on MouseMoveEx event in events window, it will be genererated automatically : customcontrol1.MouseMoveEx+=OnMouseMoveEx; but i think that the event handler doesn't know what time fire this event.

        A 1 Reply Last reply
        0
        • H hdv212

          thanks when in designer mode, double click on MouseMoveEx event in events window, it will be genererated automatically : customcontrol1.MouseMoveEx+=OnMouseMoveEx; but i think that the event handler doesn't know what time fire this event.

          A Offline
          A Offline
          amargujrathi2006
          wrote on last edited by
          #4

          Hi, Can you describe your coding flow shortly ? Eg. class customcontrol { //code of event handler } class where_you_use_customcontrol { //code of event handler } and when you want to raise that event. So my view become clear. Regards, Amar

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups