PC Review


Reply
Thread Tools Rate Thread

derive MouseEventArgs from EventArgs

 
 
Peted
Guest
Posts: n/a
 
      10th May 2007
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
 
Reply With Quote
 
 
 
 
Moty Michaely
Guest
Posts: n/a
 
      10th May 2007
On May 10, 11:14 am, Peted wrote:
> 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


On May 10, 11:14 am, Peted wrote:
> 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.

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      10th May 2007
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 Removed)

"Moty Michaely" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On May 10, 11:14 am, Peted wrote:
>> 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

>
> On May 10, 11:14 am, Peted wrote:
>> 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.
>



 
Reply With Quote
 
Brian Schwartz
Guest
Posts: n/a
 
      10th May 2007
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.

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets


<Peted> wrote in message news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Peted
Guest
Posts: n/a
 
      11th May 2007

thanks

all


On Thu, 10 May 2007 16:14:56 +0800, Peted wrote:

>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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
memcpy of a MouseEventArgs jleslie48 Microsoft C# .NET 9 20th Sep 2010 04:00 PM
get mouseeventargs Sam Microsoft VB .NET 5 29th Jun 2005 11:13 AM
MouseEventArgs, Clicks is always 1 ? Ralf Jablonski Microsoft Dot NET Framework Forms 4 6th Jul 2004 02:44 PM
MouseEventArgs SvenÅke Andersson Microsoft Dot NET Compact Framework 2 19th Mar 2004 03:11 AM
MouseEventArgs JH Microsoft C# .NET 0 8th Jul 2003 06:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:33 PM.