简体   繁体   中英

Layout manager in C#

I am trying to design a UI in C# . I come from Java background and am familiar with the different layout managers in Java.

So what I am trying to do is:

I have a Pane. To this pane I wish to add controls one below the other. In Java I would have used a BoxLayout (Y-Axis), and then just added the controls. Also the individual controls/containers could have been further customized by using different layouts for each individual container.

How do I do this in C#?

What I need to do is:

1)Add controls one below the other. Each individual control can be a collection of smaller controls.

So what I can have is something like:

Control 1 here
Control 2 here
Control 3 here

Each control can have its own layout, say BoxLayout on X axis and so on. How do I do all this?

PS: I am using WINFORMS.

I will take a stab that you are building WinForms, and suggest you look at the following controls, which are similar to the Java layout managers;

  • Panel
  • FlowLayoutPanel
  • TableLayoutPanel

A Panel will let you place controls arbitrarily within it, and you use the Dock, Anchor and Location properties to position each child control.

A FlowLayoutPanel will do what you are asking if you set the flow to 'TopDown', but everything will be left-aligned and that can't be changed I believe.

A TableLayoutPanel is going to be the most useful to you I expect. Just create the panel with 1 column, and add each control to a row. The rows can be set to AutoSize to their contents to give you the closest match to a BoxLayout I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM