I’m using a custom label to enable the forecolor when the labels disabled (By using the below)
How do I center the text as the standard lablel does when autosize is off and text alignment is set to TopCenter for exmple? I’ve tried StringFormat with the alignment options but this doesn’t align to the center.
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim LabelBrush As New SolidBrush(Me.ForeColor)
Dim SF As New StringFormat
SF.FormatFlags = StringFormatFlags.NoWrap
SF.Alignment = StringAlignment.Center
SF.LineAlignment = StringAlignment.Center
LabelBrush.Color = DisabledColor_Dark
e.Graphics.DrawString(Me.Text, Me.Font, LabelBrush, Padding.Left, Padding.Right, SF)
LabelBrush.Dispose()
LabelBrush = Nothing
End Sub
The DrawString call doesn’t look right with those padding variables.
Try this instead:
As far as matching the ContentAlignment of TopCenter, etc, you would have to change your Alignment and LineAlignment properties accordingly to how you want the text to be displayed.
Also, consider using
TextRendererinstead ofe.Graphics.DrawString(). Better output.