views:

210

answers:

1

I have a TabControl with multiple pages. On one page, I just have a label and I want it to fill the page and scroll if necessary. Despite trying what seems like every combination of anchor and dock, the label won't scroll. I've set the AutoScroll property of the page to true but no luck. I've seen articles about using a ScrollBar and manually handling scrolling, but it seems a bit crude. Is this true?

A: 

AutoScroll will only help if the children controls span an area larger than the space provided by the TabControl. Hence when using docking (which sizes the label to be constrained by the space available) it will never become large enough to force the scrollbars to appear.

Have you considered using a readonly textbox control instead? Setting this to DockStyle.Fill should get the effect you are looking for, where a scrollbar will appear if the text overflows the available space.

If you want to use a label control you will most likely need to manually size it. The following blog post by José Gallardo Salazar outlines one approach to determine how much space is required to display a given string of text (including any required word-wrapping etc). If the label control grows larger than the TabControl the AutoScroll functionality should start to automatically work.

Christopher Fairbairn
Thanks Chris, a read-only textbox would probabl be better.
Echilon