473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

derive MouseEventArgs from EventArgs

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
May 10 '07 #1
4 9581
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.

May 10 '07 #2
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]
- mv*@spam.guard.caspershouse.com

"Moty Michaely" <Mo*****@gmail.comwrote in message
news:11**********************@e51g2000hsg.googlegr oups.com...
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.

May 10 '07 #3
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
<Petedwrote in message news:lr********************************@4ax.com...
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

May 10 '07 #4

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
May 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sujith Jagini | last post by:
Hi, When we create customEventArgs, we derive the classes from eventArgs( ) and I dont understand the advantage of this inheritance. This is neither an interface nor applied as attribute. I...
4
by: Gates72 | last post by:
Hello All, I am looking for an example showing a custom EventArgs class that derives from CancelEventsArgs, and a form or control using that class in a custom event. The simpler, the better,...
3
by: Yangtsi River | last post by:
Hi, in any event procudure,there is two paras:sender As Object, e As EventArgs, i copied them-not know what they are about, and my ASPX works. I guess the sender is the control by which I...
2
by: rom | last post by:
i want to call a sub in vb.net like: Private Sub X(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) where the second argument can sometimes be...
0
by: Sujith Jagini | last post by:
Hi, When we create customEventArgs, we also derive the classes from eventArgs( ) and I dont understand the advantage of this inheritance. This is neither an interface nor applied as attribute. ...
0
by: Sujith Jagini | last post by:
Hi, When we create customEventArgs, we derive the classes from eventArgs( ) and I dont understand the advantage of this inheritance. This is neither an interface nor applied as attribute. I...
1
by: Sujith Jagini | last post by:
Hi, When we create customEventArgs, we also derive the classes from eventArgs( ) and I dont understand the advantage of this inheritance. This is neither an interface nor applied as attribute. ...
5
by: Sam | last post by:
Hi, Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs) AddHandler e.Control.MouseMove, DirectCast(CheckCursor(), System.Windows.Forms.MouseEventHandler)...
6
by: Michael.Suarez | last post by:
Consider the TextBox Control. It has a KeyPress event of type KeyPressEventHandler which passes a KeyPressEventArgs to whatever method is assigned to the event. When you set e.Handled = false...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.