Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WinC窗体中绘图相当慢_C#_.net_Winforms_Datagridview - Fatal编程技术网

C# 在WinC窗体中绘图相当慢

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

我正在创建一个自定义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事件。试试MouseEnter。鼠标停留在控件上一段时间后,将触发鼠标悬停。MouseEnter是即时的

您正在使用MouseHover事件使鼠标越过控件。试试MouseEnter。鼠标停留在控件上一段时间后,将触发鼠标悬停。鼠标是即时的

您熟悉双缓冲吗?我试过自动双缓冲,但没什么区别。你熟悉双缓冲吗?我尝试了自动双缓冲,但没有任何区别。