how to work with Splitter (or SplitContainer ?)

  • Thread starter Thread starter bonk
  • Start date Start date
B

bonk

I am trying to create a simple Form using .NET CF 2.0 that displays two
Treeviews Side-by-Side in case the device is running in landscape mode. When
the user switches to portait mode, the two treeviews shall be displayed on
top of each other. Also the user should be able to resize the two controls
by moving a horizontal (or vertical) bar. I felt that the splitter is the
perfect control for that. But unfortunately I am not sure what to do to make
it work. No matter what I do, the splitter can not be resized. I set
treeview1.dock to top, I set splitter.dock to top and I set treeview2.dock
to fill. What else do I need to do to make the splitter resizable and to
chnage the oriantation upon switch to landscape mode. Is t here an event for
the landscape/potrait mode change ?



Also the msdn says that Spiltter is now obsoloete and I should now use the
SplitContainer. But the Viusal Designer of VS 2005 does not have support
for the SplitConatainer. At east I cannot find it in the toolbox.
 
The designer does a very poor job of handling the Splitter (SplitterControl
exists only in the full framework)
Open the designer code file and edit it manually to ensure the correct order
of adding the new controls:

treeview1.Dock = Top;
splitter.Dock = Top;
treeview2.Dock = Fill;

this.Controls.Add(treeview2);
this.Controls.Add(splitter1);
this.Controls.Add(treeview1);
 
wow Splitter is a really tricky (if not buggy) control. But thank you, that
worked.

But how would change the orientation of the splitter when the user switches
to landscape mode ?

I tried it this way:
 
Alex Feinman said:
The designer does a very poor job of handling the Splitter
(SplitterControl exists only in the full framework)
Open the designer code file and edit it manually to ensure the correct
order of adding the new controls:

treeview1.Dock = Top;
splitter.Dock = Top;
treeview2.Dock = Fill;

this.Controls.Add(treeview2);
this.Controls.Add(splitter1);
this.Controls.Add(treeview1);
 
oops, sorry, I just discovered, that hitting control-enter sends the message
right away in outlook-express, strange ....

OK, thank you for your help, that worked. Splitter is a really strange (if
not buggy) control....

Now how would I change the orientation of the splitter, when the user
switches to landscape mode ?
I tried this:

private void Form1_Resize(object sender, EventArgs e)
{
if (this.Height <= this.Width)
{
splitter1.Dock = DockStyle.Left;
treeView1.Dock = DockStyle.Left;
}
else
{
splitter1.Dock = DockStyle.Top;
treeView1.Dock = DockStyle.Top;
}
}

But that just messes up the whole UI ....
 
I had a similar problem, using Splitter and switching between
ListView+TreeView,
and noticed that in compact framework, once you touch/change .Dock and/or
..Visible property, also .Heigh and/or .Width properties are internally
changed, compared to full framework, where these values are kept intouched.
So I always store, recalculate if needed and set these values, when doing
some changes.
 
Back
Top