derive MouseEventArgs from EventArgs

P

Peted

Hello

this is the click event method of a radio button


private void radioButton1_Click(object sender, EventArgs e)
{

}


what i want to do is Within this event method check is the left mouse
button has been pressed.

I cant seem to derive MouseEventArgs from this methods EventArgs.

Is there a way to cast it ?

I dont want to use onmousedown event, i want to have all my code in
this specific event method.


thanks for any help


Peted
 
M

Moty Michaely

Hello

this is the click event method of a radio button

private void radioButton1_Click(object sender, EventArgs e)
{

}

what i want to do is Within this event method check is the left mouse
button has been pressed.

I cant seem to derive MouseEventArgs from this methods EventArgs.

Is there a way to cast it ?

I dont want to use onmousedown event, i want to have all my code in
this specific event method.

thanks for any help

Peted

Hello

this is the click event method of a radio button

private void radioButton1_Click(object sender, EventArgs e)
{

}

what i want to do is Within this event method check is the left mouse
button has been pressed.

I cant seem to derive MouseEventArgs from this methods EventArgs.

Is there a way to cast it ?

I dont want to use onmousedown event, i want to have all my code in
this specific event method.

thanks for any help

Peted

Peted,

Casting the event args to MouseEventArgs will do no good. Who said the
type of EventArgs given in the Click event is MouseEventArgs?

To accomplish your needs I would suggest using the MouseDown or
MouseUp Events or get the mouse state in the Click event handler using
P/Invoke like this:

using System.Runtime.InteropServices;

class KeyInfo
{
[DllImport("user32")]
private static extern short GetKeyState(int vKey);

private const int VK_LBUTTON = 0x1;
private const int VK_RBUTTON = 0x2;

public static short IsLButtonDown() {
short keyState = GetKeyState((int)VK_LBUTTON);

return (keyState > 0 ? keyState >> 0x10
: (keyState >> 0x10) & 0x1) == 1;
}
}

of course you can adjust the code for your needs...

Hope this helps.
 
N

Nicholas Paldino [.NET/C# MVP]

I think that going the interop route is a bit much.

Rather, what the OP should do is move his code out to a separate method
(so he can contain it all in one place) and parameterize it so that it can
take which mouse button was clicked.

The OP also has to subscribe to the MouseDown and MouseUp events (for a
click, you want the MouseUp event) to determine which button was clicked.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Moty Michaely said:
Hello

this is the click event method of a radio button

private void radioButton1_Click(object sender, EventArgs e)
{

}

what i want to do is Within this event method check is the left mouse
button has been pressed.

I cant seem to derive MouseEventArgs from this methods EventArgs.

Is there a way to cast it ?

I dont want to use onmousedown event, i want to have all my code in
this specific event method.

thanks for any help

Peted

Hello

this is the click event method of a radio button

private void radioButton1_Click(object sender, EventArgs e)
{

}

what i want to do is Within this event method check is the left mouse
button has been pressed.

I cant seem to derive MouseEventArgs from this methods EventArgs.

Is there a way to cast it ?

I dont want to use onmousedown event, i want to have all my code in
this specific event method.

thanks for any help

Peted

Peted,

Casting the event args to MouseEventArgs will do no good. Who said the
type of EventArgs given in the Click event is MouseEventArgs?

To accomplish your needs I would suggest using the MouseDown or
MouseUp Events or get the mouse state in the Click event handler using
P/Invoke like this:

using System.Runtime.InteropServices;

class KeyInfo
{
[DllImport("user32")]
private static extern short GetKeyState(int vKey);

private const int VK_LBUTTON = 0x1;
private const int VK_RBUTTON = 0x2;

public static short IsLButtonDown() {
short keyState = GetKeyState((int)VK_LBUTTON);

return (keyState > 0 ? keyState >> 0x10
: (keyState >> 0x10) & 0x1) == 1;
}
}

of course you can adjust the code for your needs...

Hope this helps.
 
B

Brian Schwartz

You can also try the static Form.MouseButtons property to find out which
buttons are already pressed.

Note that this will tell you which buttons are currently pressed at the time
you check it; it will not notify you when a button becomes pressed as
MouseDown will, but if I read your post right, you are only wanting to check
the current state of the left button. Form.MouseButtonsn will tell you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top