1
votes

I am new in winforms and i have problem that i can't solve by myself.

enter image description here

I want dynamically to add buttons to "bottom right panel" from the pic. Problem is that if I need to add large number of buttons then the buttons from the bottom of mentioned panel are covered with control (panel) that follows panel from the pic. This case shows when i first add "bottom right panel" to "right panel" and then "top right panel".

If i reverse that, and first add "bottom right panel" to "right panel" and then "top right panel" to "right panel" then the "top right panel" covers two button from the top of the bottom right panel but with scroll bar of "bottom right panel" reachs all other buttons (including the buttons from the bottom of bottom right panel).

My question is how to show all of the buttons from "bottom right panel"?

Thank you in advance and i hope you understand my English.

UPDATE: Thank you guys for help but i didn't solve my problem although i tried all of yours tips. Now i give you more detail description what i want to achieve.

  1. With splitContainers i achieve what i want but only if i split "root" panel. Here is that form and you can see that i get scroll in the spliter2.panel2 and i can reach all of the buttons (that is just what i need):

enter image description here

But my form where i need to add this panel looks like this:

enter image description here

Form adds "root" panel, "root" panel ads 3 panels (two black panels are docked top and bottom) and third one panel is panel we speak about and it is docked to fill.

Now, where I try to reduce size of form i get this:

enter image description here

Now i don't get scroll in spliter2.panel2 and some of my buttons disappear. I need scroll in spliter2.panel2 and i need that scroll to reach all the buttons.

Is it possible and how? Thank you all again...

UPDATE 2: I need to add same behavior to one more form. The main diff (you can see on the picture bellow) is one more horizontal splitter on docked panel (root panel adds top, dock and bottom panels >> dock panel adds horizontal splitter >> dockPanelSplitter.Panel1 adds panel we speak about):

enter image description here

Again i don't have scroll although i set AutoScroll property of splitter3.Panel2 = true.

enter image description here

1
If you don't like the way "top right" and "bottom right" panels behave when docked, then you need to use something else. In your "right panel", add a TableLayoutPanel and set it up with once column and two rows. You'd add the "top right" and bottom right" panels to the rows in the TableLayoutPanel. Now you can control the sizing relationship of the two rows in the TableLayoutPanel... - Idle_Mind

1 Answers

1
votes

Use 2 SplitContainers, one vertical, one horizontal, the second inside Panel2 of the first and add your buttons dynamically (or through VS Designer) like this:

    private void Form1_Load(object sender, EventArgs e)
    {
        Button button = new Button();
        button.Text = "Button1";
        button.Location = new Point(0, 10);
        splitContainer2.Panel2.Controls.Add(button);

        button = new Button();
        button.Text = "Button2";
        button.Location = new Point(0, 50);
        splitContainer2.Panel2.Controls.Add(button);
    }

Result:

enter image description here

EDIT: In order to get the scroll bars in the new scenario with the other panels, do this:

    splitContainer2.Panel2.AutoScroll = true;

Result:

enter image description here