Resize a Rectangle at runtime
I need to resize a Rectangle at runtime.
I draw the Retangle on the Form1_Paint(), but unable to resize itt..
Graphics graph = this.CreateGraphics();
Pen penCurrent = new Pen(Color.Red);
Rect = new Rectangle(300, 50, 150, 75);
graph.DrawRectangle(penCurrent, Rect);
need some help!
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Mike GoldRank #50 · 30.6K pointsPosted May 27, 2007, 8:26 PM EDT
for example:
OnPaint()
{
e.Graphics.DrawRectangle(30, 30, x, y);
}
Set x and y outside of the event handler and call invalidate on the form region
OnButtonPressed (object sender, EventArg e)
{
x = x+5;
y = y + 5;
Invalidate(29, 29, x+1, y+1); // force it to redraw
}