• 쇼핑몰
  • 커뮤니티
  • 북마크

vb.net


[Controls] [vb.net] DataGridView 헤더 병합

하나를하더라도최선을
2021.05.02 11:42 183 0

본문



        dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        dgv.ColumnHeadersHeight *= 2
        AddHandler dgv.Paint, Sub(ByVal sd As ObjectByVal ee As PaintEventArgs)
                                  Dim monthes As String() = {"Total""Correct""Wrong""Score"}
                                  Dim j As Integer = 3
                                  Dim pDGV As DataGridView = CType(sd, DataGridView)
 
                                  Try
                                      While j < 18
                                          Dim r1 As Rectangle = pDGV.GetCellDisplayRectangle(j, -1True)
                                          Dim w2 As Integer = pDGV.GetCellDisplayRectangle(j + 1-1True).Width + pDGV.GetCellDisplayRectangle(j + 2-1True).Width + pDGV.GetCellDisplayRectangle(j + 3-1True).Width
                                          r1.X += 1
                                          r1.Y += 1
                                          r1.Width = r1.Width + w2 - 2
                                          r1.Height = r1.Height / 2 - 2
                                          '// e.Graphics.FillRectangle(New SolidBrush(DGV.ColumnHeadersDefaultCellStyle.BackColor), r1)
                                          If monthes((j - 3/ 4= "Score" Then
                                              ee.Graphics.FillRectangle(New SolidBrush(Color.Black), r1)
                                          Else
                                              ee.Graphics.FillRectangle(New SolidBrush(Color.DarkGray), r1)
                                          End If
                                          ee.Graphics.DrawLine(New Pen(New SolidBrush(Color.LightCyan)), r1.Left, r1.Bottom - 1, r1.Right, r1.Bottom - 1)
                                          Dim format As New StringFormat()
                                          format.Alignment = StringAlignment.Center
                                          format.LineAlignment = StringAlignment.Center
                                          ee.Graphics.DrawString(monthes((j - 3/ 4), pDGV.ColumnHeadersDefaultCellStyle.Font, New SolidBrush(Color.White), r1, format)
                                          j += 4
                                      End While
                                  Catch ex As Exception
                                  End Try
                              End Sub



댓글목록 0

등록된 댓글이 없습니다.