using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { private Rectangle RcDraw; private float PenWidth = 5; public Form1() { InitializeComponent(); } private void Form1_MouseMove(object sender, MouseEventArgs e) { Console.WriteLine("Mouse X: {0}", e.X); Console.WriteLine("Mouse Y: {0}", e.Y); } private void Form1_MouseDown(object sender, MouseEventArgs e) { // Determine the initial rectangle coordinates... RcDraw.X = e.X; RcDraw.Y = e.Y; RcDraw.Width = 5; RcDraw.Height = 5; this.Invalidate(RcDraw); } private void Form1_Paint(object sender, PaintEventArgs e) { // Draw the rectangle... e.Graphics.DrawRectangle(new Pen(Color.Blue, PenWidth), RcDraw); } } }