// mouse.cs
// C:>csc /t:winexe mouse.cs
// Well we want our program to be in a GUI window, so we need to inherit
// from Form, which is in the library 'System.Windows.Forms'.
class
SimpleWindow : System.Windows.Forms.Form
{
private void Screen_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
// Added just so you can see how you
would handle a mouse up
}
private void Screen_MouseDown(object
sender, System.Windows.Forms.MouseEventArgs e)
{
int mouse_x = e.X;
int mouse_y = e.Y;
string title = "MousePos: " +
mouse_x.ToString() + " " + mouse_y.ToString();
this.Text = title;
}
// Window constructor
SimpleWindow()
{
this.MouseUp +=
new System.Windows.Forms.MouseEventHandler(this.Screen_MouseUp);
this.MouseDown +=
new System.Windows.Forms.MouseEventHandler(this.Screen_MouseDown);
}
// Our program entry point.
static void
Main()
{
System.Windows.Forms.Application.Run(new
SimpleWindow());
}
}//
End of SimpleWindow Class |