title: Vertical Text on Right-Aligned TabControl
body: <p>Trying to have the text on each tab of the tabcontrol to be displayed vertically. Being that I've never forayed into controls and what not, i'm sorta stuck.  Found some code to get the text to display as if it were rotated to the left.  I would like it to display as if it were rotated right (vertically) on the tab.  The skeleton code is below: </p>
  
  <pre><code>Protected Sub OnDrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) Handles TabControl1.DrawItem
      'MyBase.OnDrawItem(e)'
      Dim tc As TabControl = DirectCast(sender, TabControl)
      Dim g As Graphics = e.Graphics
      Dim rectf As RectangleF
      Dim isVertical As Boolean = (tc.Alignment &gt; TabAlignment.Bottom)
      Dim off As Integer = 1 : If (e.State And sel) = sel Then off = -1
      Dim textFormat As New StringFormat(StringFormatFlags.NoClip _
                                 Or StringFormatFlags.NoWrap)
      With textFormat
          .HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show
          .Alignment = StringAlignment.Center
          .LineAlignment = StringAlignment.Center
      End With
  
  
      With e.Bounds
          If isVertical Then
              ' tabs are aligned left or right'
              If tc.Alignment = TabAlignment.Left Then
                  Dim m As New System.Drawing.Drawing2D.Matrix
                  m.Translate(0, .Height - tc.TabPages(0).Top)
                  m.RotateAt(270, New PointF(.X, .Y))
                  g.Transform = m
                  rectf = New RectangleF(.Left - tc.TabPages(0).Top, .Top + off, _
                                         .Height, .Width)
              ElseIf tc.Alignment = TabAlignment.Right Then
                  'Dim m As New System.Drawing.Drawing2D.Matrix'
                  'm.Translate(0, .Height - tc.TabPages(0).Top)'
                  'm.RotateAt(270, New PointF(.X, .Y))'
                  'g.Transform = m'
                  'rectf = New RectangleF(.Left - tc.TabPages(0).Top, .Top + off, _'
                  '                       .Height, .Width)'
                  ' Here is where the tab should go to rotate the text about 180 degrees'
              End If
          Else
              ' tabs are aligned top or bottom'
              rectf = New RectangleF(.X, .Y + off, .Width, .Height)
          End If
      End With
  
  
      Dim col As Color
      Select Case (e.State And notsf)
          Case DrawItemState.Disabled
              col = SystemColors.GrayText
          Case DrawItemState.HotLight
              col = SystemColors.HotTrack
          Case Else
              col = SystemColors.MenuText
      End Select
  
  
      g.DrawString(tc.TabPages(e.Index).Text, _
                   tc.Font, _
                   New SolidBrush(col), _
                   rectf, _
                   textFormat)
  
      If isVertical Then g.ResetTransform()
  
      If (e.State And selfoc) = selfoc Then
          ControlPaint.DrawFocusRectangle(g, _
                    [Rectangle].Inflate(e.Bounds, -1, -1))
      End If
      textFormat.Dispose()
  End Sub 
  </code></pre>