我正在为Windows Mobile开发C#应用程序。我有一个自定义控件,重写了 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是在自定义控件内绘制图像的左上角。
我认为它可以正常工作,但是当我移动图像时,它永远不会清除所有控件。我总是看到上一张图的一部分。
我做错了什么?
谢谢!