I have a simple Form such as the following:
using System; using System.Drawing; using System.Windows.Forms; namespace PaintTest { class PaintTest : Form { int _counter = 0; [STAThread] static void Main() { Application.Run(new PaintTest()); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawString(_counter.ToString(), new Font(FontFamily.GenericSerif, 10.0f), Brushes.Blue, 10.0f, 10.0f); _counter++; } } }
When the window is resized, the counter doesn’t appear to update on the screen, even though OnPaint() is getting called and the counter incremented. How do I make the Form repaint itself as the window is resized?
Add the following to your class, e.g. in its constructor:
SetStyle(ControlStyles.ResizeRedraw, true);