This is a chunk of code to set the text of a text box to align right if it exceeds the length of the text box.
Note: These bits of code are mostly for my own reference, but if anyone else finds them useful all the better.
1 2 3 4 5 6 7 8 |
Dim g As Drawing.Graphics = Me.CreateGraphics Dim TextWidth As Integer = g.MeasureString(TextBoxToBeChecked.Text, TextBoxToBeChecked.Font).ToSize.Width If (TextWidth > TextBoxToBeChecked.Width) Then TextBoxToBeChecked.TextAlign = HorizontalAlignment.Right Else TextBoxToBeChecked.TextAlign = HorizontalAlignment.Left End If |