c# - 在 C# winform 中绘图相当慢

标签 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(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/

相关文章:

.net - MS StyleCop 和 CruiseControl.NET

c# - 使用 Task.Run 运行时用户控件卡住

c# - 为什么静态类是密封的?

c# - 将 WebAPI 函数限制为授权用户?

.net - VS2010+甲骨文驱动: ORA-12154: TSN:could not resolve the connect identifier specified

c# - 为什么 DataGridViewRow.Cells[1].Value 返回 null 而不是 null?

c# - 动态从文件夹加载 winforms 图标

c# - 将控件添加到 Gridview 单元格

c# - 获取所有应用程序的列表

.net - 我无法修改的库中类的 Wcf 数据契约(Contract)