【发布时间】:2010-05-13 14:56:58
【问题描述】:
我正在尝试在 C#.Net 中为 Windows 窗体应用程序构建自己的自定义控件。目前我使用paint事件绘制一些矩形和其他图形元素。 当我现在调整应用程序表单的大小以适应桌面大小时,所有元素都被重新绘制(这正是我需要的行为),但旧的元素显示在背景中。
这是我现在正在做的事情:
Pen penDefaultBorder = new Pen(Color.Wheat, 1);
int margin = 5;
private void CustomControl_Paint(object sender, PaintEventArgs e) {
CustomControl calendar = (CustomControl)sender;
Graphics graphics = e.Graphics;
graphics.Clear(Color.WhiteSmoke);
graphics.DrawRectangle(penDefaultBorder, margin, margin, calendar.Width - margin * 2, calendar.Height - margin * 2);
//...
}
graphics.Clear 和添加 graphics.FillRectangle(...) 都不会隐藏表面上的旧矩形。
想法?谢谢大家。
【问题讨论】:
标签: c# .net graphics custom-controls resizable