我正嘗試在C#.Net中爲Windows窗體應用程序構建自己的自定義控件。目前我使用繪畫事件繪製一些矩形和其他圖形元素。 當我現在調整應用程序窗體大小以適合桌面大小時,所有元素都會重新繪製(這正是我需要的行爲),但舊的顯示在背景中。c# - 調整大小時清除表面
這裏是我現在在做什麼:
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(...)將隱藏在表面的舊矩形。
想法?謝謝你們。
這將工作;這是一個霰彈槍的方法,但它會工作。我仍然喜歡只在需要更改時渲染緩衝區,並複製OnPaint中請求的區域。 – overslacked 2010-05-13 15:36:52
嗯 - 這很簡單;-)感謝您的幫助,現在調整大小按預期工作。 – dhh 2010-05-13 15:38:23