Programmatically showing and hiding a scollbar in a multiline text

G

Guest

I want to have my textbox display a scrollbar if there is more text than will
fit, but to make it invisible if it will all fit. Is this possible?

The default behavior if all the text fits is a visible, but grayed out
scrollbar.

There doesn't appear to be a way to define this behavior using properties.

I thought about doing it manually by checking if number of lines of text was
greater than the number of lines in the textbox. But can't figure out how to
get the first value (the 2nd can be magic numbered) because the
textbox.Lines.Length property returns the number of logical lines, not the
number that are/would be displayed due to word wrapping.

Is there annother approach I've not thought of?
 
N

Nicholas Paldino [.NET/C# MVP]

Dan,

I would keep the greyed out scroll bar, to be honest, as it is pretty
much a standard.

The reason for this is that you would have to lay out all of the text in
your display again if the scrollbar is added and removed. It's just simpler
when doing the layout calcs to keep it there greyed out.

If you are going to turn the scrollbar on and off programatically in
your textbox, I would think the layout adjustment would be disconcerting.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top