|
Mouse events can be processed simply by overriding the
OnMouseDown method of the Control class.
using System; using System.Windows.Forms; class MouseSample : Form { public static void Main() { Application. Run( new MouseSample () ); } protected override void OnMouseDown( MouseEventArgs e ) { MessageBox.Show( "X:" + e.X.ToString() + " Y:" + e.Y.ToString() ); } }
The method OnMouseDown of the Control class expects a MouseEventArgs
as argument. An object of the type MouseEventArgs has two properties
X and Y for the corresponding coordinates. We use these to display
the location of a mouse click.
|