Raising an event from code

jain_mj

Member
Joined
Aug 21, 2005
Messages
17
Location
Cochin, India
Programming Experience
3-5
I need to raise the mousemove event of a button from code. ie, without actually moving the mouse. Please tell me how to do this. I also need a general idea of raising other base class events. :confused:
 
You can call your own event handlers directly if you want, but you cannot actually raise a genuine event that way. If the mouse doesn't move then there is no MouseMove event. Tell us why you want to do this and we may be able to suggest a better alternative to raising a fake event.
 
To raise an event from code, one needs to add an addhandler event.

addhandler <control name>(<object that fired the event>,<object saving the event data>)
 
Let's establish the difference between raising an event and handling an event.

If you want to raise an event, you need to perform the action that causes the event to be raised, like setting a specific property or moving the mouse. In your own classes, you can declare a delegate for your event and a procedure that uses the RaiseEvent statement to raise the associated event.

If you want to handle an event for a particular variable, you need to provide a procedure with the correct signature to handle the specified event and establish a link between the event and the procedure. You do this with either the AddHandler statement or a Handles clause. Be aware that the event is raised by the specified object whether you handle it or not.
 
I was about to make my custom button control. I need to highlight the button when mouse moves over it and depress it when clicked. so i need to repaint the control. but painting can be done only in the OnPaint event of the control. to draw on the control, i need a PaintEventArgs object which is available in the OnPaint event. So what i need is to call the OnPaint(byval sender as object, byval e as system.windows.forms.painteventargs) when mousemove event occurs.
 
Back
Top