Width of Label

  • Thread starter Thread starter jack-e
  • Start date Start date
J

jack-e

Hi,


An easy on I'm guessing!


How do I restrict the length of a label? I have tried setting the width

to say 200px but if the user inputs a continuous line of characters
it's doesn't wrap.


Thanks in advance.


Jack
 
The problem you have is not the width attribute of the label control rather
it is the continuous line of characters. You will have to reformat any
string that is longer than the maximum length of your label. Here is an
example of a function that you pass the string that you wish to space out
and the max length of the label that you wish to display:

Private Function SpaceOut(ByVal inputstring As String, ByVal len As Integer)
As String
If inputstring.Length > len Then
Return inputstring.Substring(0, len) & " " &
SpaceOut(inputstring.Substring(len + 1), len)
Else
Return inputstring
End If
End Function

So if you have a text in a variable called LongLine that want to display in
a label named lblText, you would use it like this:
lblText.Text = SpaceOut(LongLine, 30)
 
Back
Top