日期:2014-05-17 浏览次数:20830 次
public partial class Form1 : Form
{
Point pt;
public bool a ;
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (a==true)
{
Graphics dc = e.Graphics;
Pen blue = new Pen(Color.Blue, 3);
dc.DrawRectangle(blue, pt.X, pt.Y, 50, 50);
}
a = false;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
a = false;
pt.X = e.X;
pt.Y = e.Y;
this.Text = string.Format("鼠标位置:({0},{1})", pt.X, pt.Y);
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
a = true;
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
a = true;
}