Reputation: 7030
I have the following paint event (form) that is drawing the rectangle:
void LogicSimulationViewerForm_Paint(object sender, PaintEventArgs e) {
Rectangle rect = new Rectangle(100, 100, 400, 100);
Graphics c = rtbLogicCode.CreateGraphics();
c.DrawRectangle(new Pen(Color.Black, 3), rect);
}
The rectangle is shown for a brief moment and then disappears immediately. The rectangle will only show momentarily again when the user resizes the form.
How can I solve this issue?
Upvotes: 0
Views: 1355
Reputation: 17850
Don't use the Control.CreateGraphics() method, use the PaintEventArgs.Graphics property:
void LogicSimulationViewerForm_Paint(object sender, PaintEventArgs e) {
Rectangle rect = new Rectangle(100, 100, 400, 100);
e.Graphics.DrawRectangle(Pens.Black, rect);
}
Upvotes: 6