我正在创建一个自定义 DataGridView,其中复选框在鼠标悬停时显示边框。
这是我到目前为止所做的事情。
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 事件让鼠标滑过控件。请尝试使用鼠标输入。鼠标在控件上停留一段时间后会触发 MouseHover。鼠标输入是即时的
关于c# - 在 C# winform 中绘图相当慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9900001/