how to make form width equal to splitcontainer panel width

Mohan

Member
Joined
Oct 18, 2006
Messages
17
Location
bangalore
Programming Experience
1-3
in a mdi form I have put a splitcontainer control, in panel1 treeview control, in panel 2, i want to show child forms equal to width of the panel2, how to make this.
 
You don't have to make it MDI (also it will disappear behind panel). This code places form in container, set the 'child' form WindowState to Maximized and it will fill the panel.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] f [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Form2[/SIZE]
[SIZE=2]f.TopLevel = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2]SplitContainer1.Panel2.Controls.Add(f)[/SIZE]
[SIZE=2]f.Show()[/SIZE]
 
ok, instead of setting the child form Maximized add this code (before f.show in example):
VB.NET:
[SIZE=2]f.Dock = DockStyle.Fill
[/SIZE]
Now it the child form also resizes with the panel. It doesn't work with maximized form so you perhaps want to prevent this by setting MaximizeBox=False for child forms.
 
Actually ur first solution only worked for me...

even second solution also worked.

both time child form is width is not resizing...

in ur first solution the child form height was equal to the panel height it's good coz i wanted it like that.

but width of the form is not increasing...so i asked u how to increase r decrease when we move the splitter left /right.

in second solution the form height was not increasing to panel height, child form size was equal to the design time size.

so please let me know how to increase/decrease the width according to the splitter/panel moments
 
That is not what I'm seeing here. Here the docked child resizes automatically with both splitter change and form resize in any direction. Only if child is maximized I see that it doesn't work. I've attached the project.
 

Attachments

  • vbnet20-ChildFormInPanel.zip
    19 KB · Views: 72
Back
Top