Splitters and Docking

G

Guest

Has anyone really gotten the Docking and Splitter Bars to work for anyting
but the simplest application for two controls and one splitter bar filling
the whole form? If so, can you enlighten my on HOW! I even tried creating
background panels and docking them with the controls on the panels but the
docking order seems to be random! Another useless control from Microsoft I
think!
 
H

Herfried K. Wagner [MVP]

Dennis said:
Has anyone really gotten the Docking and Splitter Bars to work for anyting
but the simplest application for two controls and one splitter bar filling
the whole form? If so, can you enlighten my on HOW! I even tried
creating
background panels and docking them with the controls on the panels but the
docking order seems to be random!

Use the "Bring to foreground" and "Send into background" context menu items
of the controls in the Windows Forms designer to control the docking order.
 
C

Cor Ligthert

Dennis,

The splitter works fine when you know how, just some trying.

Your problem with the docking has nothing to do with the splitter, however
with the designer. When you use that it adds it in the way you drags it on
the form (Zorder).

It is easy to change in the designer generated code. Not efficient however
not really very expensive for performanse in my opinion is as well removing
those controls and adding them once in the load event (When you do it using
the designer you can do it everytime again when you change something)

What I find also very usefull to do is hidding and showing them. I have
forms where I have panels over panels as well splitting horizontal as
vertical. For that is however as well that Z order needed. (Z order is from
bottom to top.)

I hope this helps?

Cor
 
A

Atara

splitter control allows the user to resize THE DOCKED CONTROL that is
IMMEDIATELY BEFORE IT.
Therefore, to enable the user to resize a docked control at run
time:
1. Dock the control to be resized to an edge of a container.
2. Dock a splitter control to the same side of that container.

e.g: 1 splitter.
control1.Dock = DockStyle.Left
splitter1.Dock = DockStyle.Left
splitter1.MinExtra = 100
' Set the minimum size control2 can be sized to.
splitter1.MinSize = 75
' Set the minimum size control1 can be sized to.
control2.Dock = DockStyle.Fill
' Set control2 to fill the remaining space on the form.
Me.Controls.AddRange(New Control() {control2, splitter1,
control1}) ' Add in reverse order to ensure proper location.

e.g: 2 Splitters.
control1.Dock = System.Windows.Forms.DockStyle.Left
control1.Width = Me.ClientSize.Width \ 3
control2.Dock = System.Windows.Forms.DockStyle.Top
control2.Height = Me.ClientSize.Height * 2 \ 3
control3.Dock = System.Windows.Forms.DockStyle.Fill

splitter1.Location = New System.Drawing.Point(121, 0)
splitter1.Width = 3
splitter2.Dock = System.Windows.Forms.DockStyle.Top
splitter2.Height = 3

panel1.Controls.AddRange(New System.Windows.Forms.Control()
{control3, splitter2, control2}) ' Add in reverse order to ensure proper
location
panel1.Dock = System.Windows.Forms.DockStyle.Fill

Me.Controls.AddRange(New System.Windows.Forms.Control() {panel1,
splitter1, control1}) ' Add in reverse order to ensure proper location

Good Luck.
Atara
 
G

Guest

Thank you for your replies. I didn't know that that the Zorder affected the
way the controls were docked. It's still difficult to get the controls and
splitters where you want them.
 
G

Guest

Ok, I got the splitter to working and the panels where I want them. However,
when I add two controls and a splitter between them to a panel as chldren of
the panel, they show up ok but I can't resize the widths of the controls
using the splitter between them. It works fine if the two controls and
splitter are directly on a form but when they are children of a panel, it
doesn't work.
 
H

Herfried K. Wagner [MVP]

Dennis said:
Ok, I got the splitter to working and the panels where I want them.
However,
when I add two controls and a splitter between them to a panel as chldren
of
the panel, they show up ok but I can't resize the widths of the controls
using the splitter between them. It works fine if the two controls and
splitter are directly on a form but when they are children of a panel, it
doesn't work.

You'll have to select the control above the splitter for horizontal
splitters or the control left to the splitter for vertical splitters and
change its size. This will move the splitter and resize the control docked
on the other side of the splitter.
 
G

Guest

I'm using vb2003. I have a panel with child controls that has a listview
docked to the left, a Splitter docked left and another listview docked with
Fill. In run move, when I put the mouse on the splitter, I don't get
anything and can't resize the widths of the controls with the mouse. I works
ok in Design mode.
 
H

Herfried K. Wagner [MVP]

Dennis said:
I'm using vb2003. I have a panel with child controls that has a listview
docked to the left, a Splitter docked left and another listview docked
with
Fill. In run move, when I put the mouse on the splitter, I don't get
anything and can't resize the widths of the controls with the mouse. I
works
ok in Design mode.

I have tried the scenario you described in VS.NET 2002 (I currently don't
have VS.NET 2003 installed) and everything worked just fine.
 
G

Guest

Herfried, I got it to work. You're not going to believe this but the problem
was that I had the vertical splitter sized to only 1 pixel and I wasn't
getting the mouse over it to resize the two controls on either side of it. I
changed to splitter size to 4 pixels wide and it works fine...what a dumb
mistake! Sorry for causing you to spend time on this kind of thing but
thanks anyway as your notes gave me confidence to keep working at it for the
solution.
 
C

Cor Ligthert

Dennis,

I believe this, because I had all those same problems as you the first time
with the splitter.

:)

Cor
 
C

C-Services Holland b.v.

Dennis said:
Has anyone really gotten the Docking and Splitter Bars to work for anyting
but the simplest application for two controls and one splitter bar filling
the whole form? If so, can you enlighten my on HOW! I even tried creating
background panels and docking them with the controls on the panels but the
docking order seems to be random! Another useless control from Microsoft I
think!

The way it works for me is thinking ahead and then adding the controls
in the right order. So if I want 2 panels with a vertical splitter I add
1 panel, then the splitter, then the next panel. This seems to work for me.
 
G

Guest

Here is a generic algorithm I wrote to add multiple items to a panel with
splitters between them. This should handle between 1..N controls.

Control main = null;
Control p = null;
Spliter sp = null;
ArrayList list = new ArrayList();

....
add controls to list that you want to have splitters between
....

// loop through the list of controls that we want to add to the panel
// with a horizontal splitter between each one.
// We will loop through the list backwards to get the items to start
// at the top with the first item in the list
for (int nIndex = list.Count - 1; nIndex >= 0; nIndex--)
{
// if we already have a panel, then add the current panel to a new panel as
a fill and add a splitter
if (main != null)
{
// store a reference to the current control
p = main;

// create a new panel control that will hold the old control and the
current list item
main = new Panel();
main.Dock = DockStyle.Fill;

// add the previous control to the panel
main.Controls.Add(p);

// create a new splitter and add it to the new panel we just created
sp = new Splitter();
sp.Dock = DockStyle.Top;
main.Controls.Add(sp);

// set the previous control to dock at the top and then add it to the new
panel
// we just created
((Control)list[nIndex]).Dock = DockStyle.Top;
main.Controls.Add((Control)list[nIndex]);
}
else
{
// set the main control to the current list item control that
// we are iterating through
((Control)list[nIndex]).Dock = DockStyle.Fill;
main = (Control)list[nIndex];
}
}

// set the dock and height of final control and add it to the
// client panel we want to display it in
main.Dock = DockStyle.Top;
main.Height = (int)(panel1.Height * .5 * list.Count);
panel1.Controls.Add(main);

Although this simply adds 1..N controls with horizontal splitters between
them, it can be customized to do vertical or mixed for any number of controls.

Ashton Hobbs
ApexSQL Edit
http://www.apexsql.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top