VB2010 DataGridView 縦書きについて

タグの編集
投稿者 初心者  (高校生) 投稿日時 2015/10/6 11:14:11
VB2010 WIN7

DataGridViewのヘッダーを縦書きにしたいのですが
どうしても上手く出来ません。
ある程度は、出来たのですが位置がバラバラで真っ直ぐになりません。
何か方法がありましたらお教えください。
よろしくお願いします。
投稿者 shu  (社会人) 投稿日時 2015/10/6 13:46:37
CellPaintingにて縦書きで描画するとよいです。

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        DataGridView1.ColumnHeadersHeight = 200
        DataGridView1.Columns(0).Width = 30
    End Sub

    Private Sub DataGridView1_CellPainting(sender As Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
        If e.RowIndex = -1 AndAlso e.ColumnIndex >= 0 Then
            e.Handled = True
            e.PaintBackground(e.ClipBounds, False)
            Dim g = e.Graphics()
            Dim sf As New StringFormat()
            Dim fnt = New Font("@MS ゴシック", 16, FontStyle.Bold)
            sf.FormatFlags = StringFormatFlags.DirectionVertical
            g.DrawString(DataGridView1.Columns(e.ColumnIndex).HeaderText, fnt, Brushes.Black, e.CellBounds, sf)
        End If
    End Sub
投稿者 初心者  (社会人) 投稿日時 2015/10/7 13:26:05
shu 様

ありがとうございます。

出来ました。