Search code examples
vb6controls

VB6 Label max string length?


I have a project for fun in VB6, I'm using quite long labels and would like them to stretch the entire length of my monitor however they seem to be capped at 256 chars per line. It let's me set their caption to as long as I like but after the 256th character, the rest does not appear on the screen.

If I change it to multiline however, it will display the full text but again will automatically take a new line at the 256th character meaning it doesn't utilise the full width of my monitor.

I was wondering if anyone knows why this is, a way around it or what my options are?

Edit: After testing, using a text box and making it look like a label is an alright work around, as text boxes don't seem to have this same restriction.

Edit 2: Text boxes lack an autosize function which is crucial to my project so any further advice is appreciated.


Solution

  • According to the MS Learn Caption Property's Remarks:

    A Label control’s caption size is unlimited. For forms and all other controls that have captions, the limit is 255 characters.

    However, as you have seen this statement may not be correct. It appears to apply to Label controls as well, and the limit is actually 256 characters in my experimentation.

    I think your idea of a TextBox control should work for what you need. Since there is no AutoSize property, simply change the width of the control in the Form Resize event.

    Private Sub Form_Resize()
       Text1.Width = Me.ScaleWidth
    End Sub