DataGridView怎么设置边框才是单线边框
展开全部
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
'窗体上只需要拉出一个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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询