Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
event
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 :
[DllImport("user32.dll")]
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 18:11pm
Edited 23-Jan-13 19:33pm
v3
Comments
Sergey Alexandrovich Kryukov at 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...
—SA
Sports Kuo at 24-Jan-13 0:14am
   
Thanks of your suggestion, I'll see how to improve the event handler sturcture to meet the expected request.
Sergey Alexandrovich Kryukov at 24-Jan-13 0:18am
   
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...
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
            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();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I will give up this request, thanks for all.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 9-May-13 0:52am
   
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.
 
—SA

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


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

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