5

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.

Radu Murzea
  • 10,724
  • 10
  • 47
  • 69
Nikhil
  • 1,279
  • 2
  • 23
  • 43
  • Are you building a WinForms or WPF application? The answer will be quite different depending on this. – RJ Lohan Jul 23 '12 at 06:19
  • 1
    It's not a question of "C# vs Java". It's a question of WPF vs. WinForms. Here's Microsoft's intro to WPF: http://msdn.microsoft.com/en-us/library/ms752299.aspx See also: http://www.wpftutorial.net/LayoutProperties.html – paulsm4 Jul 23 '12 at 06:19

1 Answers1

5

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.

RJ Lohan
  • 6,497
  • 3
  • 34
  • 54
  • I can't see no Box layout here (like in java) . WIll TableLayoutPanel do the trick then? I want something like Boxlayout. – Nikhil Jul 23 '12 at 06:26