Expand and collapse winform

What I'm trying to do is expand and collapse the middle of my winform. I know that there are similar questions, but none of them do what I need. I read about usage FlowLayoutPanel, but I can't get it to work.

An example of what I want to achieve:

I have winform (example)

example

When I click button1, it should hide the text box in the middle and compress the shape to hide the space, and vice versa, when I click button2. In any case, it button3should remain below where the text field is displayed or not displayed.

, . AutoSize true AutoSizeMode GrowAndShrink.

, , . .

?

.

0 , , .

Screen shot

+3
4

, , . , Button3 , :

public partial class Form1 : Form {
  private int originalHeight;

  public Form1() {
    InitializeComponent();
    button3.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
  }

  protected override void OnLoad(EventArgs e) {
    originalHeight = this.Height;
    base.OnLoad(e);
  }

  private void button1_Click(object sender, EventArgs e) {
    textBox1.Visible = false;
    this.Height = originalHeight - textBox1.Height;
  }

  private void button2_Click(object sender, EventArgs e) {
    this.Height = originalHeight;
    textBox1.Visible = true;
  }
}

AutoSize=false; , .

, Button2 , , Button1 , .

+1

, . AutoSize - .

+1

, , , , :

, FlowLayoutPanel . . FlowDirection TopDown . AutoSize FlowLayoutPanel true AutoSizeMode GrowAndShrink.

, AutoSize true / , . , , , , . , , . , , , .

/

Instead of using two buttons, I like to use the checkbox to expand / collapse. All encoding for resizing will be reduced to adding one property binding string checkbox1.Checkedto a Visibilitytext field property :

textbox1.DataBindings.Add ("Visible", checkbox1, "Checked")

+1
source

Hide the control and set the Height property accordingly.

0
source

All Articles