Frames with windows forms

I am making a windows form program in vb.net that i want to have in a single form. My question is, what is the best way of creating an interface similar to "frames" in html.

This is what i want to do: Create two seperate areas/frames within my form. Click on a button in area/frame 1 will open/display a particular form/page in area/frame 2....sorry, it's hard to put into words.

I thought about doing this with overlapping panels with their visible property set to false. Clicking button1 sets panel1's visible property to visible to true, and sets all other panels visible property to false. But this becomes quite complicated.

Thanks in advance for any suggestions...I am new to vb.net, my experiance lies in html and other web programming...

James


Answer this question

Frames with windows forms

  • FreeToDev

    Thanks for the help, everything seems to be good, just one slight problem...

    m_ParentForm.ShowChildForm(New NewSub(m_ParentForm), True)

    NewSub is not defined, and also I'm not quite sure where I should be referencing the new subform.  I follow pretty much what you did, just those two problems.

    Thanks again,

    Dave

  • kowgli

    It sounds like you could do something like this:

    1-  Add a panel to your form, set the dock property to top.
    2-  Fill the panel with whatever controls you need to control navigation.
    3-  Add a splitter to your form, set the dock property to top.
    4-  Add a panel to your form, set the dock property to Fill.

    This will be your "shell," for lack of a better term.

    Then, create full fledged forms containing the content that needs to be displayed based on the user's actions with the controls in the frame.  When a user initiates one of the actions, you can add the corresponding full-fledged form to the second panel that was added above:

    Dim f As New ActionForm()
    f.TopLevel = False
    HostPanel.Controls.Add(f)
    f.Show()


    And now you should be good to go.  Let me know if you have questions and if that meshes with what you were thinking of for your interface.

  • Fredrik Skånberg

    Hi Dave-

    I'm not entirely sure I understand your layout.  Let's simplify it a bit.  Would a Form with a Menu and a Panel be accurate   And, when the user clicks a MenuItem, different forms appear in the Panel   And, the problem you are having is that on one of the forms, there is a button that should cause the form to disappear and a new form to appear   Is that an accurate synopsis

  • budc

    Rather than handle these operations from within the child forms, you will have significantly better luck by handling them in the Main Form.  Provide some code like this in your main form:

    Public Sub ShowChildForm(ByVal NextChild As Form, Optional ByVal CloseCaller As Boolean = False)

          If CloseCaller Then
               Panel.Controls.Clear()
          End If

          NextChild.TopLevel = False
          Me.Panel.Controls.Add(NextChild)
          NextChild.Show()
    End Sub


    Then, in your Child Forms, you can do something like this:

    Public Class Sub1
           Inherits Form

           Private m_ParentForm As MainForm

           Public Sub New(ByVal ParentForm As MainForm)
                Me.New()
                m_ParentForm = ParentForm
           End Sub

           Private Sub Go_Click.....
                m_ParentForm.ShowChildForm(New NewSub(m_ParentForm), True)
           End Sub
           
    End Class


    That should take care of it for you. Let me know if you have any questions.

  • Fwallen

    Yup thats pretty much what I'm trying to do... I'll explain it again and hopefully we'll get it figured out.

    I have one master form with one panel in it.
    One of the forms that the panel displays has a button on it.
    When the user clicks on the button, I want the current form (inside the panel) to disappear and a new form to appear in the same panel.

    The way I kinda figure it has to be coded is as follows (but it doesn't seem to be working)

    MAIN FORM (simply has a panel in it)
    NEWSUB (the form I want to show in the panel)
    SUB1  (the form that contains the button)
    ----------- Code to go into SUB1 ---------
    Private Sub Go_Click(...)
      Dim MAIN as new MAIN()
      Dim NEWSUB as new NEWSUB()

      NEWSUB.Toplevel = false
      MAIN.Panel.Controls.Clear()
      MAIN.Panel.Add(NEWSUB)
      NEWSUB.show()

    As far as I can tell this should work, but it doesn't.  If you could help me out it would be great.

    Thanks

    Dave

  • PBlais

    I'm actually doing the same thing, and I used a similar approach, but I'm stuck with one thing if you could help me out.  Basically I have 1 panel which I want to change depending on what the user clicks.  Now if they use the menu I built for them the panel changes properly, however if they try to click one of the buttons I have on the page, it doesn't refresh the panel.

    Here is the code I was using for the menu.

    Dim frm As New frm()
    frm.TopLevel = False
    Panel.Controls.Clear()
    Panel.Controls.Add(frm)
    frm.Show()

    Do you have any ideas as to how I can get it to work using a button inside the panel that I want to change

    Thanks,

    Dave

  • Frames with windows forms