user3165438
user3165438

Reputation: 2661

Auto resize Winform- messing up the controls order

I develop a winform with a big testbox and a button below.

enter image description here

I set the textbox Anchor to the 4 directions so when the winform is resized, the tetbox will be resized accordingly.
However, the button below that should not be resized is covered by the bigger textbox.
How can I prevent this?

enter image description here

Upvotes: 2

Views: 269

Answers (2)

Nasreddine
Nasreddine

Reputation: 37888

You should set up these anchors:

  • The large TextBox: Top, Right, Bottom, Left

  • The Button: Left, Bottom

  • The small TextBox: Right, Bottom, Left

enter image description here

You might want to add a MinimumSize to the form to avoid messing up the layout when it's too small.

And here's a live demo:

enter image description here

Upvotes: 2

Matthew Watson
Matthew Watson

Reputation: 109792

  1. Dock the textbox in the form using dock = Fill.
  2. Add a Panel to the control and set it to dock = Bottom.
  3. Ensure that the textbox is before the panel in the document outline (and not nested in it!). If you get this order wrong, the panel will appear obscured by the text box.
  4. Adjust the height of the text box area by dragging the line between it and the panel beneath it. You must click the panel before you can drag this line.
  5. Add your button and other control to the Panel. Look in document outline to ensure that they are properly nested in the panel.
  6. Align the button and other control as desired in the Panel.

Note: To see the document outline window: View => Other Windows => Document Outline

Upvotes: 3

Related Questions