471,325 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

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

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

Feb 7 '06 #1
4 16117
See the Control.MouseButtons property.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
<ri***@onetel.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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?.

Feb 7 '06 #2
Why not use the MouseDown and the MouseUp events?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ri***@onetel.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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

Feb 7 '06 #3
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.

Feb 8 '06 #4
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.

Feb 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Tyron | last post: by
4 posts views Thread by Raj Chudasama | last post: by
2 posts views Thread by Rudiga | last post: by
18 posts views Thread by eliss.carmine | last post: by
5 posts views Thread by Adeel | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.