R
Roger Crawfis
I am writing a 3D graphics demo for my students, and thought I had a really
slick solution for handling the interaction with the mouse. There are
several ways to interact with a 3D world, and I have attached a mouseDown
event handler to my OpenGL panel (control). What I want to do, is based upon
which mouse button was pressed associate the proper mouseMove event handler
with the control. OK, so I have a From with several controls, including a
few OpenGL controls I created. I attached the mousedown to an OpenGL
control. In the callback I want to associate the MouseMove and MouseUp event
handlers. I first tried something like this in the MouseDown event handler:
m_MouseMoveDelegate = new MouseEventHandler( camera.Trackball );
this.MouseMove += m_MouseMoveDelegate;
m_MouseUpDelegate = new MouseEventHandler( My_MouseUp );
this.MouseUp += m_MouseUpDelegate;
This associates the mouse handlers with the entire Form though, not the
control. I am rather clueless on the sender semantics. I tried casting it to
my UserControl (OpenGLPanel), but that led to very bad behavior. Not sure
why. I also need to retained the mouse position of the mouse down event.
The problem above is either the "this" identifiers, or trying to save the
mouse position from the mouse down event. Casting this to screen space
provides somewhat better behavior, but not ideal.
Questions:
1) Is there something fundamentally wrong with this design?
2) Is the sender one of the controls I registered the MouseDown event
handler to?
3) In particular, is it the control in which I pressed the mouse?
4) Can I associate a MouseMove event to the sender? Note, I do not want to
embed my form logic in here and test for which control, etc.
FYI. The mouseUp event simply removes the event handlers:
// Disconnect the MouseEventHandler
this.MouseMove -= m_MouseMoveDelegate;
this.MouseUp -= m_MouseUpDelegate;
slick solution for handling the interaction with the mouse. There are
several ways to interact with a 3D world, and I have attached a mouseDown
event handler to my OpenGL panel (control). What I want to do, is based upon
which mouse button was pressed associate the proper mouseMove event handler
with the control. OK, so I have a From with several controls, including a
few OpenGL controls I created. I attached the mousedown to an OpenGL
control. In the callback I want to associate the MouseMove and MouseUp event
handlers. I first tried something like this in the MouseDown event handler:
m_MouseMoveDelegate = new MouseEventHandler( camera.Trackball );
this.MouseMove += m_MouseMoveDelegate;
m_MouseUpDelegate = new MouseEventHandler( My_MouseUp );
this.MouseUp += m_MouseUpDelegate;
This associates the mouse handlers with the entire Form though, not the
control. I am rather clueless on the sender semantics. I tried casting it to
my UserControl (OpenGLPanel), but that led to very bad behavior. Not sure
why. I also need to retained the mouse position of the mouse down event.
The problem above is either the "this" identifiers, or trying to save the
mouse position from the mouse down event. Casting this to screen space
provides somewhat better behavior, but not ideal.
Questions:
1) Is there something fundamentally wrong with this design?
2) Is the sender one of the controls I registered the MouseDown event
handler to?
3) In particular, is it the control in which I pressed the mouse?
4) Can I associate a MouseMove event to the sender? Note, I do not want to
embed my form logic in here and test for which control, etc.
FYI. The mouseUp event simply removes the event handlers:
// Disconnect the MouseEventHandler
this.MouseMove -= m_MouseMoveDelegate;
this.MouseUp -= m_MouseUpDelegate;