日期:2014-05-17 浏览次数:20784 次
Rectangle rc;
public Form1()
{
InitializeComponent();
rc = new Rectangle(5, 5, 0, 0);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
BufferedGraphicsContext current = BufferedGraphicsManager.Current;
BufferedGraphics bg;
bg = current.Allocate(this.CreateGraphics(), this.DisplayRectangle);
Graphics g = bg.Graphics;
g.Clear(Color.LightGray);
Brush mybush = new SolidBrush(Color.Black);
g.FillRectangle(mybush, new Rectangle(0, 0, 400, 400));
Brush mybush2 = new SolidBrush(Color.Red);
g.FillRectangle(mybush2, rc);
bg.Render();
g.Dispose();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
rc.Width = e.X;
rc.Height = e.Y;
this.Invalidate(rc,true);
//this.Invalidate(new Rectangle(0, 0, 5, 5), true); //上面换成这行效果还好
}