Is there any way to distribute text across a label or textbox like in Access (other than to enter spaces manually)?
Printable View
Is there any way to distribute text across a label or textbox like in Access (other than to enter spaces manually)?
I've never seen(or heard of) a distribute text align. Could you provide an example or a more accurate description?
Not |......hello......|
But |h...e...l...l...o|
Sure you could create your own custom label control and do whatever you want with it.
Basically you would determine the width of the label and the total width of the string.
take the remainder and divide it by the number of letters + 1.
Manually position each letter in the control's paint event.
The more difficult part would be to handle text that is too wide for the control.
i liked the show a lot. Loved the theme song.
projecttoday:
This is just a rough off the cuff piece of code. But I am sure it could be adapted for your needs.
Attachment 137167Code:Public Class DistributedLabel
' UserControl
Public Property mText As String = ""
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Dim Txt As String = mText
If Txt.Length = 0 Then Exit Sub
With e.Graphics
Dim Remainder As Integer = CInt(Me.ClientRectangle.Width - .MeasureString(Txt, Me.Font).Width)
Dim Spacer As Integer = Remainder \ (Txt.Length + 1)
Dim BB As SolidBrush = New SolidBrush(Me.BackColor)
Dim FB As SolidBrush = New SolidBrush(Me.ForeColor)
.FillRectangle(BB, Me.ClientRectangle)
Dim X As Integer = Spacer
For i = 0 To mText.Length - 1
Dim C As Char = mText.ToArray(i)
If i = 0 Then X = Spacer \ 2
.DrawString(C, Me.Font, FB, New Point(X, 2))
X = CInt(X + (.MeasureString(C, Me.Font).Width + Spacer))
Next
BB.Dispose()
FB.Dispose()
End With
End Sub
End Class
Did a quick few tests. I tried using an inherited Label instead of a generic usercontrol.
It didn't buy anything for the effort.
I'd go with the usercontrol and add vertical alignments.
(Top, Middle, Bottom)