1

I'm reading a Windows Forms book and I came to one example which is pretty confusing to me.

enter image description here

Here are two pictures, the first is the initial state, and the second is when the user click the Hide button. This form contains two split containers, one horizontal, and one vertical, which is in the right panel of horizontal one.

The book says:

One of the best characteristics of docked designs is that they easily accommodate hidden or modified controls. To implement

this design, two panels are placed in the left region of the SplitContainer, one named pnlFileList and the other named pnlShow. However, only one of these panels is shown at a time. The contents of the rest of the window automatically resize themselves to accommodate the additional view when it is displayed


private void cmdHide_Click(object sender, System.EventArgs e)
{
    splitContainer1.Panel1Collapsed = true;
    pnlShow.Visible = true;
}
private void cmdShow_Click(object sender, System.EventArgs e)
{
    pnlShow.Visible = false;
    splitContainer1.Panel1Collapsed = false;
}

And I made it, but the problem is with the button which appears when the left panel of the SplitContainer is collapsed.

I don't know where to put the panel "pnlShow"
If I put it on the right side of the horizontal SplitContainer control, it will disappear also.

Any suggestions?

1 Answers1

1

The quote from the book doesn't seem accurate to me. You can't place pnlShow inside the "left region" of the SplitContainer because it will not be visible once you set the Panel1Collapsed property to true.

Instead, you can place the pnlShow on the left to the SplitContainer and set its Dock property to Left. Also, you don't seem to actually need a Panel in this case since it only contains one Button. You can simply use a Button only. Anyhow, your form would look something like this in design-time:

Design-time view

Then, your code should work fine.

Some remarks:

  • Of course, if you decided to use a button without a panel, you'd need to use YourButtonName.Visible instead of pnlShow.Visible.
  • If you found that the button (panel) on the left covers the SplitContainer, you just need to right-click on the SplitContainer and select "Bring to front".
  • It's preferred to use "btn" as a prefix for the Button name instead of "cmd". The latter was kind of widely used in the classic visual basic language, because it used to be called CommandButton. In the .NET world, the standard is to use "btn" instead.

Finally, based on what I mentioned in the last point above and the look of the screenshots in your question, this book seems to be quite outdated and was written based on the early versions of the .NET framework, so unless you have to study this book specifically, I would recommend you find a more recent book or tutorials.