It depends on where you mouse event is being triggered - if it's part of the TicketGroupNodeControl, then the instance of the control that triggered the event is passed to you in the
sender
parameter of the event handler - all you have to do is cast it to the appropriate type and use it.
If it isn't, then the control that the mouse was over when the button was clicked will be supplied - so if your group control contains the controls you are searching in the comments, then it's already available via the
sender
parameter.
Use the debugger, and have a look at the parameter - it may help you work out what is going on.
am not sure what your talking about there ?
I am using a class and creating an instance of this class in side of the paint routine of picturebox1 say.
This is in paint
Dim betline1 As New TicketGroupNodeControl
Then after I have drawn the 30 rectangles .
I am wanting to use the mousedown event and mousemove event
to check if the mouse pointer is in the first rectangle.contains(e.location) when the left mouse button is pressed .
If so drag the square then update the location when released.
But when I use the mouse event args.
betline1.variable or instance is not valid in this scope. because it was created in paint sub.
I guess my question is how do i pass this on to allow the mouse events to work .
OK...we're going to have to go back a couple of steps here, because what you are trying to do is not correct!
The first thing is that you should not create your objects in the Paint event handler, for two reasons:
1) It needs to be as short and "snappy" as it can or it will impact your UI badly.
2) Paint is a "frequent flyer" event - it gets triggered
a lot: every single time the system needs to show the user a change.
Which means that your objects for display should not be created in the Paint event - they need to be ready when the Paint event is handled. Think about it: when you "drag" one of your squares, you need the paint event handled in order to show it moving! :laugh:
So start off by creating your squares in the container for your squares (probably your form, but I'd use a UserControl myself - don't worry about that, you'll come to them later).
Your squares need to be available inside the Paint event (so they can be drawn) and inside other events as well - MouseDown and MouseMove need them as well - otherwise they can't all work together to move and display your items.
So create your squares as part of the containing class - probably the form - and use them in the handlers. Look at adding the squares as part of the Form.Shown event and call Invalidate when you want to update the display.
Does that make sense?