0
我正在開發和C#應用程序Windows Mobile。我有一個自定義控件,用OnPaint覆蓋來繪製用戶隨指針移動的圖像。我自己的OnPaint方法是這樣的:顯示圖像的自定義控件:移動圖像
protected override void OnPaint(PaintEventArgs e)
{
Graphics gxOff; //Offscreen graphics
Brush backBrush;
if (m_bmpOffscreen == null) //Bitmap for doublebuffering
{
m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
}
gxOff = Graphics.FromImage(m_bmpOffscreen);
gxOff.Clear(Color.White);
backBrush = new SolidBrush(Color.White);
gxOff.FillRectangle(backBrush, this.ClientRectangle);
//Draw some bitmap
gxOff.DrawImage(imageToShow, 0, 0, rectImageToShow, GraphicsUnit.Pixel);
//Draw from the memory bitmap
e.Graphics.DrawImage(m_bmpOffscreen, this.Left, this.Top);
base.OnPaint(e);
}
的imageToShow它的圖像。
的rectImageToShow它以這種方式對事件onResize受到初始化:
rectImageToShow =
new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height);
this.Top和this.Left是的左上角繪製自定義控件內的圖像。
我認爲它可以正常工作,但是當我移動圖像時,它永遠不會清除所有的控件。我總是看到以前繪圖的一部分。
我在做什麼錯了?
謝謝!
它適用於: e.Graphics.Clear(Color.White); – VansFannel 2009-03-01 09:17:28