By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Enum constant for "Left + Right" click of MouseButton.

P: n/a
Hello, In my Application i want to know when user clicks both the
"Left" and "Right" buttons of the Mouse.
I am getting a number like this "3145728". But the MouseButtons Enum
contains only Left, Right, Middle, None, XButton1 and XButton2.
I am using .NET 1.1 version.

How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right
click not added to the Enum? Can anyone help me?

Jan 19 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Where are you getting that number?

Chaitanya wrote:
Hello, In my Application i want to know when user clicks both the
"Left" and "Right" buttons of the Mouse.
I am getting a number like this "3145728". But the MouseButtons Enum
contains only Left, Right, Middle, None, XButton1 and XButton2.
I am using .NET 1.1 version.

How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right
click not added to the Enum? Can anyone help me?
Jan 19 '07 #2

P: n/a
For combined you use the &&, for example

if(Mouse.Right && Mouse.LEFT)
//do something
"Chaitanya" <ch**************@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
Hello, In my Application i want to know when user clicks both the
"Left" and "Right" buttons of the Mouse.
I am getting a number like this "3145728". But the MouseButtons Enum
contains only Left, Right, Middle, None, XButton1 and XButton2.
I am using .NET 1.1 version.

How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right
click not added to the Enum? Can anyone help me?

Jan 19 '07 #3

P: n/a

DeveloperX wrote:
Where are you getting that number?
Press Left and Right buttons of the mouse and then Drag.
On MouseMove event, i checked e.Button.
Its showing e.Button = 3145728

Jan 19 '07 #4

P: n/a
Sorry totally ignore my post, i was thinking of something else.


"Daniel" <Da*****@vestryonline.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
For combined you use the &&, for example

if(Mouse.Right && Mouse.LEFT)
//do something
"Chaitanya" <ch**************@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
>Hello, In my Application i want to know when user clicks both the
"Left" and "Right" buttons of the Mouse.
I am getting a number like this "3145728". But the MouseButtons Enum
contains only Left, Right, Middle, None, XButton1 and XButton2.
I am using .NET 1.1 version.

How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right
click not added to the Enum? Can anyone help me?


Jan 19 '07 #5

P: n/a
To recover from my earlier error:

This is how you could do it and this does work, check your output tab as you
click:

public partial class Form1 : Form

{

public bool _mouseLeft = false;

public bool _mouseRight = false;

public Form1()

{

InitializeComponent();

}

private void Form1_MouseDown(object sender, MouseEventArgs e)

{

MouseButtons m = e.Button;

switch (m)

{

case MouseButtons.Left:

_mouseLeft = true;

break;

case MouseButtons.Right:

_mouseRight = true;

break;

}

if (_mouseRight && _mouseLeft)

Console.WriteLine("Both buttons are pressed");

Console.WriteLine("Button down " + m.ToString());

}

private void Form1_MouseUp(object sender, MouseEventArgs e)

{

MouseButtons m = e.Button;

switch (m)

{

case MouseButtons.Left:

_mouseLeft = false;

break;

case MouseButtons.Right:

_mouseRight = false;

break;

}

Console.WriteLine("Button up " + m.ToString());

}

}

Jan 19 '07 #6

P: n/a
I hope this doesnt post twice, i had a prob first time but this how you
could do it, check your output tab for results as you click:

public partial class Form1 : Form

{

public bool _mouseLeft = false;

public bool _mouseRight = false;

public Form1()

{

InitializeComponent();

}

private void Form1_MouseDown(object sender, MouseEventArgs e)

{

MouseButtons m = e.Button;

switch (m)

{

case MouseButtons.Left:

_mouseLeft = true;

break;

case MouseButtons.Right:

_mouseRight = true;

break;

}

if (_mouseRight && _mouseLeft)

Console.WriteLine("Both buttons are pressed");

Console.WriteLine("Button down " + m.ToString());

}

private void Form1_MouseUp(object sender, MouseEventArgs e)

{

MouseButtons m = e.Button;

switch (m)

{

case MouseButtons.Left:

_mouseLeft = false;

break;

case MouseButtons.Right:

_mouseRight = false;

break;

}

Console.WriteLine("Button up " + m.ToString());

}

}
Jan 19 '07 #7

P: n/a
Oh I see, sorry, this works, it will print . unless the left button is
held down regardless of what other buttons are held down at the same
time, the buttons are or'ed together.
if(((int)e.Button & (int)MouseButtons.Left) 0)
{
Console.WriteLine("Left");
}
else
{
Console.WriteLine(".");
}

Console.WriteLine(((int)e.Button).ToString()); shows that all the
individual buttons are powers of 2.

Chaitanya wrote:
DeveloperX wrote:
Where are you getting that number?

Press Left and Right buttons of the mouse and then Drag.
On MouseMove event, i checked e.Button.
Its showing e.Button = 3145728
Jan 19 '07 #8

P: n/a
Hello, In my Application i want to know when user clicks both the
"Left" and "Right" buttons of the Mouse.
I am getting a number like this "3145728". But the MouseButtons Enum
contains only Left, Right, Middle, None, XButton1 and XButton2.
I am using .NET 1.1 version.

How can i convert "3145728" to MouseButtons Enum? why Mouse Left+Right
click not added to the Enum? Can anyone help me?
MouseButtons.Right = 2097152, MouseButtons.Left = 1048576. When you add
them, you get your number.

You can combine values yourself:
MouseButtons.Right | MouseButtons.Left

That's what the "This enumeration has a FlagsAttribute attribute that
allows a bitwise combination of its member values" remark is about in
http://msdn2.microsoft.com/en-us/lib...ns(VS.71).aspx
Hans Kesting
Jan 19 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.