Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently trying create a event sub that is located on a separate class then the object is on. Currently btn1, btn2 is on frm1, while btn3, btn4 is on frm2. In class1 I want a event sub that whenever a mouse-down event occurs in any of the buttons (btn1, btn2, btn3, btn4), it will run through code to change the mouse-down button's background image to a separate image. There is also another event sub for Mouse-Up.

What I have tried:

VB
Public Sub _MouseDown(sender As Button, e As MouseEventArgs) Handles frm1.btn1.mousedown, frm1.btn2.mouusedown, frm2.btn3.mouusedown, frm2.btn4.mouusedown
      sender.BackgroundImage = My.Resources.btnDown
  End Sub
  Public Sub _MouseUp(sender As Button, e As MouseEventArgs) Handles frm1.btn1.mouseup, frm1.btn2.mouusedup, frm2.btn3.mouuseup, frm2.btn4.mouuseUp
      sender.BackgroundImage = My.Resources.btnUp
  End Sub
Posted
Updated 25-Apr-18 17:10pm

1 solution

You cannot. You have two create two event handlers, one for each form, and implement the same logic in both of them.

You could also create a subclass of the Button class which would handle the MouseDown and MouseUp events. You could then use these custom buttons of yours in both your forms, without having to rewrite the event handlers.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900