Inspired by the layout of Lotus Notes, I developed something that, in my opinion, would be useful in this situation. It contains only one button between the panels, which switch the rotation / smoothing state of one panel, but can be easily changed to use two buttons to control the right and left panels. It uses two separated containers, one docked inside the other, and the mouseMove event on the "middle" panel to simulate the drag and drop of a splitter ( Moving a control by dragging it with the mouse in C # / a>). In addition, I use the ClientSizedChanged event for containers to handle the logic of switching image buttons instead of the method that minimizes / expands the panel ( Detect when SplitContainer crashed changes ).
Design:
splitContainer1 ββββββββββββββ€ββββββββββββββββββββββββββββββββββ β β splitContainer2 (docked fill) β β β ββββββββββββββ€βββββββββββββββββ β β β β β β β β β β Button(s) β β β β β β [<>] β β β β β β β β β β β ββββββββββββββ§βββββββββββββββββ β ββββββββββββββ§ββββββββββββββββββββββββββββββββββ splitContainer2.Dock = DockStyle.Fill; splitContainer1 = splitContainer2.IsSplitterFixed = true; splitContainer2.Panel1.Cursor = Cursors.VSplit;
Anchor button left or right (or set several buttons inside the tableLayout control). Just make sure there is still some part of the panel available for click / drag.
Set the maximum value of the middle panel to low. The size depends on how much you need your buttons.
The code:
The panel will switch to the opposite state.
If you really need one button with two parts instead of two buttons or a toggle button, you will need to click the coordinates of the mouse and have different logic depending on where the click occurred.
private void btnExpand_Click(object sender, EventArgs e) { splitContainer1.Panel1Collapsed = !splitContainer1.Panel1Collapsed; }
Gender logic related to expansion / failure. I decided to use this event, because in my program there are several ways: the user can minimize / expand panels.
private void splitContainer1_Panel2_ClientSizeChanged(object sender, EventArgs e) { if (splitContainer1.Panel1Collapsed) { splitContainer2.Panel1.Cursor = Cursors.Default; this.btnExpand.Image = imageExpand; } Else { splitContainer2.Panel1.Cursor = Cursors.VSplit; this.btnExpand.Image = imageCollapse; } }
Cancel panel resizing due to fake splitter movement
private void splitContainer2_Panel1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (eX + splitContainer1.SplitterDistance < 40) { while (splitContainer1.SplitterDistance > 1) splitContainer1.SplitterDistance--; splitContainer1.Panel1Collapsed = true; } else if ((eX + splitContainer1.SplitterDistance) * 1.00 / this.Width * 1.00 < .75) splitContainer1.SplitterDistance += eX; else Cursor.Current = Cursors.No; } }