How load user control into panel on split container in Win app?

R

Ronald S. Cook

I have a Windows app with a split container (SplitContainer1) that contains
two panels (Panel1, Panel2).

I would like to load a user control (utcMyTest) into Panel2 on form load.

Can someone please tell me the line(s) of code to do that?

Also, is there an easy/dynamic way to unload whichever user control is
already in there? I'm assuming only one can be in there at a time, right?

Thanks,
Ron
 
R

Ryan S. Thiele

Try this:
Panel2.controls.add(utcMyTest)

to unload:
Panel2.controls.remove(utcMyTest)
 
P

Phill W.

Ronald said:
I have a Windows app with a split container (SplitContainer1) that contains
two panels (Panel1, Panel2).

I would like to load a user control (utcMyTest) into Panel2 on form load.

utcMyTest = New ....
Panel2.Controls.Add( utcMyTest )
Also, is there an easy/dynamic way to unload whichever user control is
already in there?

Just in case you manage to get more than one in there ...

For i As Integer = Panel2.Controls.Count - 1 To 0 Step -1
Panel2.Controls.Remove( Panel2.Controls.Item(i) )
Next

A For Each loop /might/ work, but you would be removing items from a
collection as you loop through it - generally not a good idea.

HTH,
Phill W.
 

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