Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a bunch of labels to a C# form and then scroll the form vertically?

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.

like image 659
fraXis Avatar asked Feb 25 '23 14:02

fraXis


1 Answers

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".

like image 142
Cody Gray Avatar answered Apr 28 '23 15:04

Cody Gray