Replace splitcontainer panel usercontrol  
Author Message
TitanX





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

Hi,

I'm using the splitcontainer control, assigning a usercontrol to panel2.

How do I change the currently assigned usercontrol to panel2 from within the current usercontrol which is currently assigned to panel2.

ie. a button is clicked on the current usercontrol and now must be replaced with a new usercontrol.

Cheers

John



Visual C#8  
 
 
Markku Behm





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

Hi

You can do it in the same way as normal panel.

Insted of 'Panel2' you must use '<splitContainerName>.Panel2' where <splitContainerName> is your component name example 'splitContainer1'.

Yours Markku


 
 
Markku Behm





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

Btw. Why you don't put both controls to form at design mode, change other visible to false and then on button click change those visible values.

Markku


 
 
TitanX





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

Will that use more resources as the 20 usercontrols I have would all need to be allocated and have database connections each

Thanks

John


 
 
TitanX





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

>You can do it in the same way as normal panel.

>Insted of 'Panel2' you must use '<splitContainerName>.Panel2' where <splitContainerName> is your component name >example 'splitContainer1'.

How do i get access to the splitcontainer from the usercontrol which was first assigned to the panel2

Usercontrol is assigned for the first time as

private void Form1_Load(object sender, EventArgs e)

{

us = new UserControl1();

us.Dock = DockStyle.Fill;

this.splitContainer1.Panel2.Controls.Add(us);

}

But inside the UserControl1 is there a reference to the splitcontainer form object

Cheers

John


 
 
Markku Behm





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

Hi

Inside usercontrol use this.Parent property to reference to the container (Panel2) and if you need reference to the spitcontainer use this.Parent.Parent

Markku


 
 
Bobby Stark





PostPosted: Visual C# General, Replace splitcontainer panel usercontrol Top

Using this.Parent.Parent does not work is says "Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement"