Mouse, is there way of reading mouse button state without relying on event

  • Thread starter Thread starter riscy
  • Start date Start date
R

riscy

I have a button with mouse_click event when pushed. However it does not
generates mouse down event.
To fix this I could poll the mouse state every 10mSec and see if the
mouse button remains down or up.
I did a search on internet & MSDN and to my surprise, it seem there is
no simple solution to actually read the flag relating to mouse button
state.

Is there way around this?.

thanks
 
Nicholas
That would not work because window button-click take prededance over
the mouseup and mouse down. You have button on a form and mouse mouse
pointer and click button this event fired. I insert a bool variable on
both mousedown and mouseup event, but this flag did not change. I not
sure if this is true for mouseup. i have code within the window
button-click event routine that need to monitor the mouse button
state.

I use this button to zoom in and out the X-Y chart, once I click that
button, it zoom once and pause for 500mSec. The routine then check if
the mouse button is still down and repeat the zoom every 150mSec. This
save clicking many time.
 
I attached the code example, which work okay but it use DoEvent() which
is bad programming practice.

private void XBtnZoomIn_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SM.MouseZoomInX(SD.iZChOrder,SD.iWidth/2,120);
Application.DoEvents();
SC.Invalidate();
DateTime nextEvent = DateTime.Now.AddMilliseconds(dInitialDelay);
TimeSpan ts;
m_XIsZoomInDown = true;
while (m_XIsZoomInDown)
{
System.Threading.Thread.Sleep(5);
ts = nextEvent.Subtract(DateTime.Now);
if (ts.TotalMilliseconds <= 0)
{
SM.MouseZoomInX(SD.iZChOrder,SD.iWidth/2,120);
nextEvent = DateTime.Now.AddMilliseconds(dRepeatDelay);
SC.Invalidate();
}
Application.DoEvents();
}
}
}
private void XBtnZoomIn_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
m_XIsZoomInDown=false;
}

What I try to do is to moinitor the change of the left mouse button so
I can quit the loop.
 
Back
Top