11-04-24, 05:05 PM
جرب هذا ..
كود :
Private Sub DataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
If e.RowIndex = -1 AndAlso e.ColumnIndex >= 0 Then
e.PaintBackground(e.ClipBounds, True)
Dim rect As Rectangle = Me.dataGridView1.GetColumnDisplayRectangle(e.ColumnIndex, True)
Dim titleSize As Size = TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font)
If Me.DataGridView1.ColumnHeadersHeight < titleSize.Width Then
Me.DataGridView1.ColumnHeadersHeight = titleSize.Width
End If
e.Graphics.TranslateTransform(0, titleSize.Width)
e.Graphics.RotateTransform(-90.0F)
e.Graphics.DrawString(e.Value.ToString(), Me.Font, Brushes.Black, New PointF(rect.Y - (dataGridView1.ColumnHeadersHeight - titleSize.Width), rect.X))
e.Graphics.RotateTransform(90.0F)
e.Graphics.TranslateTransform(0, -titleSize.Width)
e.Handled = True
End If
End Subكود :
Me.DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
Me.DataGridView1.ColumnHeadersHeight = 50
Me.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader
AddHandler DataGridView1.CellPainting, AddressOf DataGridView1_CellPaintingقناتنا على اليوتوب
