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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald S. Cook

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

    I have a Windows app with a split container (SplitContainer 1) 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


  • Ryan S. Thiele

    #2
    Re: How load user control into panel on split container in Win app?

    Try this:
    Panel2.controls .add(utcMyTest)

    to unload:
    Panel2.controls .remove(utcMyTe st)

    ---
    Another way to load multiple controls is:
    Panel2.controls .AddRange(new control() {MyArrayOfContr ols})

    Hope this helps.


    "Ronald S. Cook" <rcook@westinis .comwrote in message
    news:OUhH64RUHH A.4260@TK2MSFTN GP06.phx.gbl...
    >I have a Windows app with a split container (SplitContainer 1) 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
    >
    >

    Comment

    • Phill W.

      #3
      Re: How load user control into panel on split container in Win app?

      Ronald S. Cook wrote:
      I have a Windows app with a split container (SplitContainer 1) 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.

      Comment

      Working...