高手帮忙看看一个C# panel画图的问题
下述代码在resize的时候,矩形会有残影,请问如何解决,C#新学,请教了。
-----
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;
public class Form2 : Form
{
internal class MyTableControl: System.Windows.Forms.Panel
{
private int itemHeight;
private int itemWidth;
public int ItemHeight
{
get { return itemHeight; }
set { this.itemHeight = value; }
}
public int ItemWidth
{
get { return itemWidth; }
set { this.itemWidth = value; }
}
public MyTableControl():base()
{
SetStyle(ControlStyles.UserPaint,true);
SetStyle(ControlStyles.AllPaintingInWmPaint,true);
SetStyle(ControlStyles.DoubleBuffer,true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Brush wbrush = new SolidBrush(Color.White);
Rectangle TabRect = Rectangle.FromLTRB(this.ClientRectangle.Left,this.ClientRectangle.Top+ItemHeight,this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-1);
e.Graphics.FillRectangle(wbrush, TabRect);
}
}
private int m_BorderWidth = 4;
private MyTableControl tableControl;
public Form2()
{
tableControl = new MyTableControl();
tableControl.Parent = this;
tableControl.Location = new Point(2*m_BorderWidth,0);
tableControl.ItemHeight =24;
tableControl.ItemWidth = 50;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
tableControl.Size = new Size(ClientRectangle.Right - 4*m_BorderWidth,ClientRectangle.Height -8*m_BorderWidth);
}
static void Main()
{
Application.Run(new Form2());
}
}