我有一个简单的表格如下:
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++;
}
}
}
调整窗口大小时,即使调用OnPaint()
并且计数器递增,计数器也不会在屏幕上更新。当窗口调整大小时,如何使表单重新绘制?
答案 0 :(得分:2)
将以下内容添加到您的课程中,例如:在它的构造函数中:
SetStyle(ControlStyles.ResizeRedraw, true);