2
我正在創建一個自定義DataGridView,其中CheckBox在引發MouseHover時顯示邊框。在C#winform中繪圖很慢
這是我到目前爲止所做的。
void checkBox_MouseLeave(object sender, EventArgs e)
{
//showBorder defines whether the border is drawn.
this.showBorder = false;
this.DataGridView.InvalidateCell(this);
}
void CheckBoxMouseHover(object sender, EventArgs e)
{
this.showBorder = true;
this.CheckBox.BringToFront();
this.DataGridView.InvalidateCell(this);
}
protected override void Paint(...........)
{
..........
if (showBorder)
{
GraphicsPath border=new GraphicsPath();
border.AddRectangle(new Rectangle(checkBoxPosition.X-1,checkBoxPosition.Y-1,checkBoxSize.Width+1,checkBoxSize.Height+1));
graphics.DrawPath(new Pen(borderColor,1),border);
}
}
但是速度太慢,我不得不等待大約半秒鐘才能看到邊框顯示。 無論如何,MouseLeave工作正常。 那麼我該如何改善這裏的表現呢?
另外,如何定製複選框?例如背景顏色等。
你是否熟悉雙緩衝? http://www.bobpowell.net/doublebuffer.htm – 2012-03-28 01:37:47
我試過自動雙緩衝,並沒有區別。 – user840866 2012-03-28 01:59:38