Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

custom checkbox and vertical text

Status
Not open for further replies.

hambakahle

Programmer
Nov 5, 2014
8
US
Because of screen real estate limitations, I thought checkboxes with vertical text would be useful and decided to give custom controls an inaugural attempt. Below is a simple control class: unfortunately it renders a proper checkbox graphic, but no visible text. I'd appreciate comments as to what I am overlooking or doing wrong.

Code:
Public Class VerticalCheckbox
    Inherits System.Windows.Forms.CheckBox

    Public Property VerticalText As String
    Private fmt As New StringFormat

    Public Sub New()
        fmt.Alignment = StringAlignment.Center
        fmt.FormatFlags = StringFormatFlags.DirectionVertical
    End Sub

    Public Shadows Property Text 'Overrides raiseserror
        Get
            Return _VerticalText
        End Get
        Set(ByVal value)
            _VerticalText = value
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
        Dim cx As Single = (Left + Right) / 2
        Dim cy As Single = (Top + Bottom) / 2
        Dim g As Graphics = e.Graphics
          g.DrawString(_VerticalText, Font, Brushes.Black, New Rectangle(cx, cy, 100, 20), fmt)

    End Sub

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top