DataGridView怎么设置边框才是单线边框

 我来答
就烦条0o
2016-08-05 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46492
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
Public Class Form1
'窗体上只需要拉出一个DataGridView,其它什么也不用做
Dim sPen As Pen = New Pen(Color.Black, 1)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 6 '6列,也可在设计时添加
DataGridView1.Rows.Add(10) '10行
DataGridView1.RowHeadersVisible = False
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
DataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None
DataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None
DataGridView1.GridColor = Color.Red '为了截图,设为红色
sPen.Color = Color.Red
For i As Integer = 0 To 10
For j As Integer = 0 To 5
DataGridView1.Rows(i).Cells(j).Value = CInt(Rnd() * 1000)
Next
Next
End Sub

Private Sub DataGridView1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGridView1.Paint
Dim range As New System.Drawing.Rectangle
Dim dLeft, dTop As Single
Dim a As Graphics = DataGridView1.CreateGraphics
For i As Integer = 0 To 5
range = DataGridView1.GetCellDisplayRectangle(i, -1, False)
dLeft = range.Left + range.Width - 1
dTop = 0
a.DrawLine(sPen, dLeft, dTop, dLeft, range.Height)
Next

Dim sHeight As Single = 0, sWidth As Single = 0
'For i = 0 To DataGridView1.Rows.Count - 1'此列设置为无行标题,若有,请去掉注释
' sHeight += DataGridView1.Rows(i).Height
'Next
'range = DataGridView1.GetCellDisplayRectangle(0, -1, False)
'a.DrawLine(sPen, range.Left - 1, 0, range.Left - 1, sHeight)

For i = 0 To DataGridView1.Columns.Count - 1
sWidth += DataGridView1.Columns(i).Width
Next
range = DataGridView1.GetCellDisplayRectangle(0, -1, False)
a.DrawLine(sPen, 0, range.Height, sWidth, range.Height)
End Sub
End Class
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式