C# 在WinC窗体中绘图相当慢
我正在创建一个自定义DataGridView,其中当鼠标悬停时,复选框显示一个边框 这是我到目前为止所做的C# 在WinC窗体中绘图相当慢,c#,.net,winforms,datagridview,C#,.net,Winforms,Datagridview,我正在创建一个自定义DataGridView,其中当鼠标悬停时,复选框显示一个边框 这是我到目前为止所做的 void checkBox_MouseLeave(object sender, EventArgs e) { //showBorder defines whether the border is drawn. this.showBorder = false; this.DataGridView.InvalidateCell(t
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很好用。
那么,我该如何改进这里的性能呢
此外,如何自定义复选框?例如,背景色等。您正在使用鼠标在控件上移动的MouseHover事件。试试MouseEnter。鼠标停留在控件上一段时间后,将触发鼠标悬停。MouseEnter是即时的您正在使用MouseHover事件使鼠标越过控件。试试MouseEnter。鼠标停留在控件上一段时间后,将触发鼠标悬停。鼠标是即时的您熟悉双缓冲吗?我试过自动双缓冲,但没什么区别。你熟悉双缓冲吗?我尝试了自动双缓冲,但没有任何区别。