当前位置:编程学习 > C#/ASP.NET >>

WinForm中的DataGridView单击单元格时,在内容周围总有一条虚线线怎么去掉。

在winform里的datagridview里,单元格鼠标单击时总会有一条虚线,是虚线哦。我怎么也去不掉,在网上也没有搜到,难道是太简单了。 --------------------编程问答-------------------- Focus的虚框,不太好处理 --------------------编程问答-------------------- 看看cellborderstyle 属性 --------------------编程问答-------------------- 这一条虚线 朋友们都知道是吧
怎么处理呢,老板看起来不好看,非得让处理,不行啊。高手呢?帮帮忙!!! --------------------编程问答-------------------- 简单的做法就是:
搂主重绘一个背景颜色的框来覆盖这个焦点框 --------------------编程问答-------------------- 刚给搂主写了个代码,搂主可以参考:
private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
    DataGridViewCell cell = this.dataGridView1.CurrentCell;
    if (!this.dataGridView1.ContainsFocus || cell == null)
        return;
    Rectangle bounds = this.GetCellBounds(cell);
    bounds.X += 1;
    bounds.Y += 1;
    bounds.Width -= 2;
    bounds.Height -= 2;
    using (Pen pen = new Pen(SystemColors.Highlight))
    {
        e.Graphics.DrawRectangle(pen, bounds);
    }
}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    this.dataGridView1.Invalidate();
}


上面使用了一个函数:GetCellBounds
这个函数搂主可以从下面贴中,我在13楼写的代码:
http://topic.csdn.net/u/20081129/11/4eb00964-d24c-4332-8164-9823c89e47b6.html --------------------编程问答-------------------- 好贴 --------------------编程问答-------------------- 经典! --------------------编程问答-------------------- 这个还没有做过啊 --------------------编程问答-------------------- 好贴,顶起来! --------------------编程问答-------------------- 好贴 顶起来 --------------------编程问答-------------------- 顶起来
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,