472,139 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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
8 4433
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
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

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
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
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
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
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
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.

Similar topics

16 posts views Thread by Alex Clark | last post: by
44 posts views Thread by Viken Karaguesian | last post: by
7 posts views Thread by the_grove_man | last post: by
reply views Thread by leo001 | 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.