Click here to Skip to main content
13,591,489 members
Rate this:
Please Sign up or sign in to vote.
See more:
I wrote a window application, the case is below :

a. there is one panel (say PanelA)
b. I assigned events to this panel panelA :
PanelA.MouseDown += new MouseEventHandler(PanelA_MouseDown);
PanelA.MouseMove += new MouseEventHandler(PanelA_MouseMove);
PanelA.MouseUp += new MouseEventHandler(PanelA_MouseUp);

c. when click left mouse button on panelA, panelA_MouseDonw event will be invoked.
d. when I click and hold left mouse button and move cursor, continuous
panelA_MouseMove event will then be invoked, and will be recoreded in system
when previous one is not yet completed.
e. in PanelA_MouseMove (say MM1), it will do more jobs and will take much time,
so that the next mouse move evnet (say MM2) has to wait until this mouse move
event MM1 is completed.

the question now is :
1. during MM1, I release the left mouse button, and of course, I would not let MM2
be executed.
2. so I add a code to detect if the left mouse button is released or not
(by using if(e.button==mousebuttons.left)), if false, then skip this mouse move
3. however, since the panelA_MouseUp event is detected only after MM1/MM2 are
completed, I can not get the real time mouse button state.

the question is :
How can I get the real time mouse button state, so that I can stop MM2 be executed ?

Thanks of your kind prompt for this issue.

Plus, I've successfully verified the function below :
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

long CheckForScrollBars_Horizontal()
    long windowStyle;
    windowStyle = GetWindowLong(TreeView1.Handle, (-16));
    return (windowStyle & 0x00100000L);

so that I can get the vertical scroll state of the TreeView1 object.

May I ask if there is any similar way to get the real time of mouse button state
as above code ?
Posted 21-Jan-13 17:11pm
Updated 23-Jan-13 18:33pm
Sergey Alexandrovich Kryukov 21-Jan-13 23:37pm
Totally wrong approach. You only need mouse data coming from event args of the handler methods, always. If you need more help, you need to explain what you want to achieve. Also, you might do something weird in some of your event handlers. The execution of each handler should be fast, not holding the UI thread...
Sports Kuo 24-Jan-13 0:14am
Thanks of your suggestion, I'll see how to improve the event handler sturcture to meet the expected request.
This is a too general phrase... I cannot see how can you improve anything by deviating from the customary processing model. Perhaps you could see it if you explain your idea in detail, but I doubt it...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

StringBuilder sb = new StringBuilder();
if ((MouseButtons & MouseButtons.Left) != 0) sb.Append("Left, ");
if ((MouseButtons & MouseButtons.Right) != 0) sb.Append("Right, ");
if ((MouseButtons & MouseButtons.Middle) != 0) sb.Append("Middle, ");
myTextBox.Text = sb.ToString();
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I will give up this request, thanks for all.
Kuo, why did you post this where you would only allowed to post answers, solutions, something to help people?
Worse, why did you self-accept it formally?
Did you know that many lost their membership account for this kind of abuse, as this is often considered as cheating?

I don't want to bring it to the attention of the community (abuse forum) because you have only two such cases, but please undo it.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.180618.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100