Pergunta

I have a form in C# (WinForm). It looks like this:


(LOGO)

blank space for labels that I add through code (I can fit 10 labels in this space)

(close button)


The blank space can hold about 10 labels.

I am stumped on how I would make this form scrollable if I want to add 20 labels? If I add 20 labels via code, then the 11th label will overlap with my close button and the 12th+ label(s) will run off the end of the form.

How do I make just the blank space portion of my form scrollable where I am creating the labels? I don't want to use a listbox.

Thanks.

Foi útil?

Solução

Place all controls inside a panel and use scrollbar control.

Understand .NET Scrollbars

Outras dicas

You should try using either a TableLayoutPanel or a FlowLayoutPanel as a container for your Label controls.

A TableLayoutPanel will allow you a finer level of control over where your labels are positioned. Like an HTML table, you specify the exact cell position (using row and column coordinates) of each control.

By contrast, a FlowLayoutPanel will handle the positioning of its contents automatically, either in a vertical or horizontal layout configuration. The positioning is determined by the order in which you add the controls, allowing you to achieve a dynamic layout with a minimal amount of fuss.

Either will allow you to add your label controls to it at run-time and size itself appropriately. In order for layout panel to be scrollable, make sure that you set its AutoScroll property to "True".

Maybe a FlowLayoutPanel with AutoScroll set to true and FlowDirection set to TopDown.

You could use a FlowLayoutPanel.

Add as many labels you need and enable AutoScroll on the FlowLayoutPanel.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top