Change label height at runtime

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,885
Office Version
  1. 365
Platform
  1. Windows
Hi all

I'm using a label within a frame, on a form, so that I can have a lot of lines of info in the label, and allow the user to scroll down through them.
The number of lines of info on the label change, so the height of the label control needs to change dynamically.

I'm having trouble changing the height of the label at runtime - if I set the label's height to say, 500, then at runtime (in the initialize event) - using:
Code:
userform1.label1.height = 1500
.......doesn't alter the height, so I can't see the rows of info at the bottom of the label.

I've even tried incrementing the label's height as each additional line of data's added to it, but that doesn't work either.

Any bright ideas, anyone.

Thanks, in advance
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
hmmmm - My height of the entire monitor is like 1000 - I can use like 100 and 300 for label height and it updates my height of a label on a useform fine - I made it yellow so I could see it.
 
Upvote 0
Thanks for the reply.

I've found the problem, which wasn't that the label height wasn't changing, but that I needed to set the height of the frame's scrollbar to that of the label so that the label could be fully visible when scrolled.
I've ended up with:
Code:
        With .Frame1
            .ScrollHeight = .Label1.Height + 50
        End With

Thanks again for the reply, though.
 
Upvote 0
Sykes

Couldn't you use a control like a textbox which would have a scroll-bar 'built-in'?
 
Upvote 0
Hi Norie

Yes, I began doing that, but then had it in the back of my mind that there was a max length of 255 characters in a textbox (unless one did a bit of clever didgery-doo) and this project sometimes needs more than that, so I went with a label, which has turned out pretty well, actually.

Thanks for the reply though.
 
Upvote 0
Sykes

That's not a limit I've heard of, I added 100 lines, about 2600 characters, with carriage returns to a textbox.

Looked OK and the only jiggery-pokery was the creation of the dummy text.

Anyway if you have what you want then that's the important part and it's probably easier to get the formatting with a label.:)
 
Upvote 0
Norie
I tried to use a textbox with a VbCrLF - but it did not work - is there another property you have to change or is it cuz I used the LF - so does that mean that your textbox now works as what used to be called a RichTextbox (I think that is what it was called-it is no longer supported - but I liked it).
 
Upvote 0
Did you see some weird characters where you expected line breaks?

That's what I saw before changing the MultiLine property to True/False.

As for RichTextBox's, I think they are still around somewhere.

Yep, just checked - when I goto Additional Controls... there's a Microsoft RichTextBox control (richtx32.ocx).

Can't actually add it though - not trusted apparently.:)
 
Upvote 0
Thanks as always, Norie.
As you mentioned formatting - I think I know the answer, but is there a way to format only PART of the text in a label's caption?
I'm writing a few hundred lines to the label's caption, and it would be icing-on-the-cake to be able to have one part of each line's text in a different colour.

I'm using:
Code:
 Label1.Caption = Label.Caption & chr(10) & some text & " £" & a variable & some more text
Ideally the variable would be in red, when the rest of the text would be in the label's default colour.

Ta, as always.....
 
Upvote 0
sykes

Not with the standard label control as far as I know.

All the 'standard' controls for userforms have pretty basic formatting.

There are other additional controls that have more options but if you were distributing whatever it is you are doing then you might run into some problems.

I suppose one way of displaying something with 'proper' formatting would be to use a Web Browser control.

Not 100% sure how you would do that but it would definitely involve HTML and possibly having to save that HTML somewhere.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top