public
partial
class
Form4 : Form
{
private Point point = new Point( 0 , 0 );
private System.Drawing.Rectangle rectangle = new Rectangle( 0 , 0 , 0 , 0 );
private bool isdrawselect;
public Form4()
{
InitializeComponent();
}
private void Form4_Load( object sender, EventArgs e)
{
}
private void Form4_MouseDown( object sender, MouseEventArgs e)
{
point = e.Location;
isdrawselect = true ;
}
private void Form4_MouseMove( object sender, MouseEventArgs e)
{
if (isdrawselect)
{
rectangle.Height = Math.Abs(e.Y - point.Y);
rectangle.Width = Math.Abs(e.X - point.X) ;
rectangle.X = e.X > point.X ? point.X : e.X;
rectangle.Y = e.Y > point.Y ? point.Y : e.Y;
System.Drawing.Graphics gp = CreateGraphics();
gp.Clear(BackColor);
gp.DrawRectangle(Pens.Red, rectangle);
label5.Text = " height= " + rectangle.Height;
label6.Text = " width= " + rectangle.Width;
}
label1.Text = " X= " + e.X;
label2.Text = " Y= " + e.Y;
label3.Text = " point.X= " + point.X;
label4.Text = " point.Y= " + point.Y;
}
private void Form4_MouseUp( object sender, MouseEventArgs e)
{
isdrawselect = false ;
}
}
{
private Point point = new Point( 0 , 0 );
private System.Drawing.Rectangle rectangle = new Rectangle( 0 , 0 , 0 , 0 );
private bool isdrawselect;
public Form4()
{
InitializeComponent();
}
private void Form4_Load( object sender, EventArgs e)
{
}
private void Form4_MouseDown( object sender, MouseEventArgs e)
{
point = e.Location;
isdrawselect = true ;
}
private void Form4_MouseMove( object sender, MouseEventArgs e)
{
if (isdrawselect)
{
rectangle.Height = Math.Abs(e.Y - point.Y);
rectangle.Width = Math.Abs(e.X - point.X) ;
rectangle.X = e.X > point.X ? point.X : e.X;
rectangle.Y = e.Y > point.Y ? point.Y : e.Y;
System.Drawing.Graphics gp = CreateGraphics();
gp.Clear(BackColor);
gp.DrawRectangle(Pens.Red, rectangle);
label5.Text = " height= " + rectangle.Height;
label6.Text = " width= " + rectangle.Width;
}
label1.Text = " X= " + e.X;
label2.Text = " Y= " + e.Y;
label3.Text = " point.X= " + point.X;
label4.Text = " point.Y= " + point.Y;
}
private void Form4_MouseUp( object sender, MouseEventArgs e)
{
isdrawselect = false ;
}
}