Working with Panels ???

Hi

I intend using 1 form with multiple layers to display different information. So I am attempting to use panels on my form to do this. I am going to use hide and visible commands to display the required panel depending on user selection.

Is there an easy way to work with multiple panels when in design view

As once a panel overlays another one I cant access the bottom panel with out physically moving the top panel out of the way. I have tried the bring to the front, send to the back and also the option select panel1 (which is the hidden one) it gets select but it still remains hidden behind the top panel (i.e panel2).

It's going to be almost impossible to work like this if I have loads of panels on one form and I have to repeatly move them all around just to get to the one I want..

Any ideas anyone

thanks

lee



Answer this question

Working with Panels ???

  • Ninja the code freak

    This is quite an age old problem. I've found the best way is to make user controls: name them appropriately, and put them onto your form either at run time or design time.

    There may be other methods. I've gone through precisely what you've said. However, think about it: do you really need all those panels (Of course, depends on what you are doing with them)



  • Rick0124

    Hi I Have one form which contains a panel control "panel1"

    I have also a added to the project a usercontrol, "Usercontrol1", which you can add controls to just like in a form.

    Using the following code you can add or remove which userscontrols  you wish to view in the form

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim mycontrol As UserControl1 = New UserControl1

    Me.Panel1.Controls.Add(mycontrol)

    End Sub

    This code has two buttons one to add and one to remove the Usercontrol.

    By placing the new instance of the contol outside of the two button methods it becomes available to both methods.

     

    Public Class Form1

    Private mycontrol As UserControl1 = New UserControl1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    'Dim mycontrol As UserControl1 = New UserControl1

    Me.Panel1.Controls.Add(mycontrol)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    'Dim mycontrol As UserControl1 = New UserControl1

    Me.Panel1.Controls.Remove(mycontrol)

    End Sub

    End Class

    You should check if the panel contains a control before adding one to overcome the problem of one control hiding under the other like this:

    Lets say we have two user controls Control1 and Control2

    if I were going to add Usercontrol1 i need to check if the panel contains UserControl2 and remove it if true

    for example

    If panel1.controls.contains(usercontrol2) then
    panel1.controls.remove(usercontrol2)
    usercontrol2 = Nothing
    End IF

    panel1.contrls.add(usercontrol1)

    You can also dock the control to fill the Panel

    usercontrol1.dock =DockStyle.fill

    Hope this helps Ron


  • PreFishing

    Hey,

    if you have more then lets say two panels on a form you should really do not doing it the "Bring To Front" way. As said before the best way is to design them aside the mother form and programatically insert them at run time.

    This link is in german but since code is pretty international I would recommend to have a look on they way its done there:

    http://www.microsoft.com/germany/msdn/library/vs2005/samples/anwendungen/windowsclient/default.mspx

    You can download the code and build the solution as you want.

    Bye


  • Working with Panels ???