Windows Forms Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Stark

    Windows Forms Question

    Hello,

    I'm *just* delving into Windows forms-based programming without the benefit
    of any books, etc. I have a background in light ASP.NET work, so forgive me
    if this is a really basic question related to Windows GUI.

    I've created a "Form1.vb" file in my project, added a menustrip, etc. When a
    user clicks on a menu item, how do I get it to show a new form in the same
    window?

    I'm basically asking how to create a Windows forms application with more
    than 1 form. :) All the examples on the internet of this type of programming
    typically show one form.

    I'm trying to understand how to create a standard UI (i.e. window size,
    title, menustrip, etc) and then change the content of the form based on what
    the user wants to do.

    Thanks. :)

    Scott

  • James Hahn

    #2
    Re: Windows Forms Question

    There's a good discussion here:

    Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET

    However, your last paragraph seems to contradict the approach described
    there - opening different forms (with different content) is one way of
    allowing your user to perform different tasks. Changing the content of the
    current form is a different way of allowing your user to perform different
    tasks. Of course, you can use both procedures within the one application,
    but they are different programming techniques.

    If you are talking about using a form template so that you are using
    different forms but with a consistency in a number of basic controls on the
    form, and you don't want to be separately adding and tweaking those repeated
    controls, then you are talking about subclassing the form. See

    Windows Forms Inheritance

    "Scott Stark" <scott@webservi cesinc.comwrote in message
    news:OrErch4GJH A.4760@TK2MSFTN GP05.phx.gbl...
    Hello,
    >
    I'm *just* delving into Windows forms-based programming without the
    benefit of any books, etc. I have a background in light ASP.NET work, so
    forgive me if this is a really basic question related to Windows GUI.
    >
    I've created a "Form1.vb" file in my project, added a menustrip, etc. When
    a user clicks on a menu item, how do I get it to show a new form in the
    same window?
    >
    I'm basically asking how to create a Windows forms application with more
    than 1 form. :) All the examples on the internet of this type of
    programming typically show one form.
    >
    I'm trying to understand how to create a standard UI (i.e. window size,
    title, menustrip, etc) and then change the content of the form based on
    what the user wants to do.
    >
    Thanks. :)
    >
    Scott

    Comment

    • Family Tree Mike

      #3
      Re: Windows Forms Question

      At first I thought you were asking how to make a form similar to MS Access,
      where many forms are initated inside the main form. Later it seems to me
      that you are describing something more like MS Outlook, which changes
      its contents based on what the user wants (email lists, contacts, calendar).

      Which is closer to what you are after?

      "Scott Stark" <scott@webservi cesinc.comwrote in message
      news:OrErch4GJH A.4760@TK2MSFTN GP05.phx.gbl...
      Hello,
      >
      I'm *just* delving into Windows forms-based programming without the
      benefit of any books, etc. I have a background in light ASP.NET work, so
      forgive me if this is a really basic question related to Windows GUI.
      >
      I've created a "Form1.vb" file in my project, added a menustrip, etc. When
      a user clicks on a menu item, how do I get it to show a new form in the
      same window?
      >
      I'm basically asking how to create a Windows forms application with more
      than 1 form. :) All the examples on the internet of this type of
      programming typically show one form.
      >
      I'm trying to understand how to create a standard UI (i.e. window size,
      title, menustrip, etc) and then change the content of the form based on
      what the user wants to do.
      >
      Thanks. :)
      >
      Scott

      Comment

      • Scott Stark

        #4
        Re: Windows Forms Question

        Hi Mike,

        Thank's for the response. I'm talking about more of an Outlook-style
        functionality. If the user chooses something from the left-hand menu, the
        "content" pane changes to that particular form.

        Scott

        "Family Tree Mike" <FamilyTreeMike @ThisOldHouse.c omwrote in message
        news:ejn7t19GJH A.740@TK2MSFTNG P03.phx.gbl...
        At first I thought you were asking how to make a form similar to MS
        Access,
        where many forms are initated inside the main form. Later it seems to me
        that you are describing something more like MS Outlook, which changes
        its contents based on what the user wants (email lists, contacts,
        calendar).
        >
        Which is closer to what you are after?
        >
        "Scott Stark" <scott@webservi cesinc.comwrote in message
        news:OrErch4GJH A.4760@TK2MSFTN GP05.phx.gbl...
        >Hello,
        >>
        >I'm *just* delving into Windows forms-based programming without the
        >benefit of any books, etc. I have a background in light ASP.NET work, so
        >forgive me if this is a really basic question related to Windows GUI.
        >>
        >I've created a "Form1.vb" file in my project, added a menustrip, etc.
        >When a user clicks on a menu item, how do I get it to show a new form in
        >the same window?
        >>
        >I'm basically asking how to create a Windows forms application with more
        >than 1 form. :) All the examples on the internet of this type of
        >programming typically show one form.
        >>
        >I'm trying to understand how to create a standard UI (i.e. window size,
        >title, menustrip, etc) and then change the content of the form based on
        >what the user wants to do.
        >>
        >Thanks. :)
        >>
        >Scott
        >

        Comment

        • Scott Stark

          #5
          Re: Windows Forms Question

          Hi James,

          Sub-classing seems to be more along the lines of what I'm looking for. I'll
          look into that, but it seems that then I'll be able to make Form1 and Form2
          inherit the base controls from, say "BaseForm" and then add the required
          functionality to Form1 and Form2.

          However, how do I get Form2 to display when the user is looking at Form1?
          Form2.Show() would open a new window? I want to "replace" Form1 with Form2
          in the same window, if that makes sense.

          "James Hahn" <jhahn@yahoo.co mwrote in message
          news:OS6bvc5GJH A.1156@TK2MSFTN GP05.phx.gbl...
          There's a good discussion here:

          Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET
          >
          However, your last paragraph seems to contradict the approach described
          there - opening different forms (with different content) is one way of
          allowing your user to perform different tasks. Changing the content of
          the current form is a different way of allowing your user to perform
          different tasks. Of course, you can use both procedures within the one
          application, but they are different programming techniques.
          >
          If you are talking about using a form template so that you are using
          different forms but with a consistency in a number of basic controls on
          the form, and you don't want to be separately adding and tweaking those
          repeated controls, then you are talking about subclassing the form. See

          Windows Forms Inheritance
          >
          "Scott Stark" <scott@webservi cesinc.comwrote in message
          news:OrErch4GJH A.4760@TK2MSFTN GP05.phx.gbl...
          >Hello,
          >>
          >I'm *just* delving into Windows forms-based programming without the
          >benefit of any books, etc. I have a background in light ASP.NET work, so
          >forgive me if this is a really basic question related to Windows GUI.
          >>
          >I've created a "Form1.vb" file in my project, added a menustrip, etc.
          >When a user clicks on a menu item, how do I get it to show a new form in
          >the same window?
          >>
          >I'm basically asking how to create a Windows forms application with more
          >than 1 form. :) All the examples on the internet of this type of
          >programming typically show one form.
          >>
          >I'm trying to understand how to create a standard UI (i.e. window size,
          >title, menustrip, etc) and then change the content of the form based on
          >what the user wants to do.
          >>
          >Thanks. :)
          >>
          >Scott
          >

          Comment

          • James Hahn

            #6
            Re: Windows Forms Question

            Like I said, your second paragraph contadicts your description of what you
            are trying to do.

            If you subclass a form then you create a new form, with its own design and
            functionality, and open and close that form as needed. This can be done as a
            selection by the user from a controlling form (dashboard-style) or it can be
            in a rotating format, where the user moves from one form to the the next in
            a sequence, returning to the start after having completed the task. Because
            the forms are subclassed they can be set up to have some predefined
            components that are identical from form to form and are maintained at one
            location only - the class for the form. You can use modality to require the
            user to work on one form at a time, if appropriate. But each task is carried
            out in its own form.

            The format you are describing involves using one form only, with some
            components that are fixed in place and are always visible and enabled and
            some components that come and go according to the current task. This is not
            subclassing - there is only one form. You are simply dynamically enabling,
            disabling, hiding and moving controls on the form to present a form layout
            that is relevant to the current task.

            I suppose you could do this by using multiple forms, setting them up to have
            some common components, and forcing each form to open with the size and
            position of the form from which it was started, hiding the startup form each
            time. This would fool the user into thinking there was only one form and the
            contents simply changed slightly depending on the task. But it seems a bit
            pointless to set the project up as multiple forms and then go to all that
            trouble to make it look like there's only one.

            Or, perhaps you are talking about an MDI form.

            MDI Changes in Visual Basic .NET

            "Scott Stark" <email@scottsta rk.comwrote in message
            news:ev51x8%23G JHA.1160@TK2MSF TNGP05.phx.gbl. ..
            Hi James,
            >
            Sub-classing seems to be more along the lines of what I'm looking for.
            I'll look into that, but it seems that then I'll be able to make Form1 and
            Form2 inherit the base controls from, say "BaseForm" and then add the
            required functionality to Form1 and Form2.
            >
            However, how do I get Form2 to display when the user is looking at Form1?
            Form2.Show() would open a new window? I want to "replace" Form1 with Form2
            in the same window, if that makes sense.
            >

            Comment

            • Family Tree Mike

              #7
              Re: Windows Forms Question

              Here is code that I am using to control the right panel of a split container
              based on an item in a treeview selected in the left panel. The form
              contained in the right panel depends on what type of node was selected.
              Hopefully this gets you started. The description of "s" should not be too
              important other than there is a Type property which the form type needs to
              be based upon.

              GEDCOM.GEDCOM_5 5.Section s = (GEDCOM.GEDCOM_ 55.Section)e.No de.Tag;
              splitContainer1 .Panel2.Control s.Clear();
              if (s == null) return;

              if (s.Type == "INDI")
              {
              IndividualUI ui = new IndividualUI();
              ui.TopLevel = false;
              splitContainer1 .Panel2.Control s.Add(ui);
              ui.Dock = DockStyle.Fill;
              ui.Show();
              }
              else if (s.Type == "FAM")
              {
              FamilyUI ui = new FamilyUI();
              ui.TopLevel = false;
              splitContainer1 .Panel2.Control s.Add(ui);
              ui.Dock = DockStyle.Fill;
              ui.Show();
              }


              "Scott Stark" <email@scottsta rk.comwrote in message
              news:u5NgA7%23G JHA.1160@TK2MSF TNGP04.phx.gbl. ..
              Hi Mike,
              >
              Thank's for the response. I'm talking about more of an Outlook-style
              functionality. If the user chooses something from the left-hand menu, the
              "content" pane changes to that particular form.
              >
              Scott
              >
              "Family Tree Mike" <FamilyTreeMike @ThisOldHouse.c omwrote in message
              news:ejn7t19GJH A.740@TK2MSFTNG P03.phx.gbl...
              >At first I thought you were asking how to make a form similar to MS
              >Access,
              >where many forms are initated inside the main form. Later it seems to me
              >that you are describing something more like MS Outlook, which changes
              >its contents based on what the user wants (email lists, contacts,
              >calendar).
              >>
              >Which is closer to what you are after?
              >>
              >"Scott Stark" <scott@webservi cesinc.comwrote in message
              >news:OrErch4GJ HA.4760@TK2MSFT NGP05.phx.gbl.. .
              >>Hello,
              >>>
              >>I'm *just* delving into Windows forms-based programming without the
              >>benefit of any books, etc. I have a background in light ASP.NET work, so
              >>forgive me if this is a really basic question related to Windows GUI.
              >>>
              >>I've created a "Form1.vb" file in my project, added a menustrip, etc.
              >>When a user clicks on a menu item, how do I get it to show a new form in
              >>the same window?
              >>>
              >>I'm basically asking how to create a Windows forms application with more
              >>than 1 form. :) All the examples on the internet of this type of
              >>programming typically show one form.
              >>>
              >>I'm trying to understand how to create a standard UI (i.e. window size,
              >>title, menustrip, etc) and then change the content of the form based on
              >>what the user wants to do.
              >>>
              >>Thanks. :)
              >>>
              >>Scott
              >>
              >

              Comment

              • Jack Jackson

                #8
                Re: Windows Forms Question

                A form is a window. You can display different content in a form, or
                you can create more forms and display them. There is no concept of
                replacing one form with another, except for MIDI child windows where
                you show one or more child windows in a containing parent window.

                The easiest way to display different content in a form is to have two
                or more containers (e.g. Panel) in a form, and make one visible at a
                time.

                On Sun, 21 Sep 2008 06:37:27 -0700, "Scott Stark"
                <email@scottsta rk.comwrote:
                >Hi James,
                >
                >Sub-classing seems to be more along the lines of what I'm looking for. I'll
                >look into that, but it seems that then I'll be able to make Form1 and Form2
                >inherit the base controls from, say "BaseForm" and then add the required
                >functionalit y to Form1 and Form2.
                >
                >However, how do I get Form2 to display when the user is looking at Form1?
                >Form2.Show() would open a new window? I want to "replace" Form1 with Form2
                >in the same window, if that makes sense.
                >
                >"James Hahn" <jhahn@yahoo.co mwrote in message
                >news:OS6bvc5GJ HA.1156@TK2MSFT NGP05.phx.gbl.. .
                >There's a good discussion here:
                >http://msdn.microsoft.com/en-us/libr...29(VS.71).aspx
                >Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET
                >>
                >However, your last paragraph seems to contradict the approach described
                >there - opening different forms (with different content) is one way of
                >allowing your user to perform different tasks. Changing the content of
                >the current form is a different way of allowing your user to perform
                >different tasks. Of course, you can use both procedures within the one
                >application, but they are different programming techniques.
                >>
                >If you are talking about using a form template so that you are using
                >different forms but with a consistency in a number of basic controls on
                >the form, and you don't want to be separately adding and tweaking those
                >repeated controls, then you are talking about subclassing the form. See
                >http://msdn.microsoft.com/en-us/libr...13(VS.71).aspx
                >Windows Forms Inheritance
                >>
                >"Scott Stark" <scott@webservi cesinc.comwrote in message
                >news:OrErch4GJ HA.4760@TK2MSFT NGP05.phx.gbl.. .
                >>Hello,
                >>>
                >>I'm *just* delving into Windows forms-based programming without the
                >>benefit of any books, etc. I have a background in light ASP.NET work, so
                >>forgive me if this is a really basic question related to Windows GUI.
                >>>
                >>I've created a "Form1.vb" file in my project, added a menustrip, etc.
                >>When a user clicks on a menu item, how do I get it to show a new form in
                >>the same window?
                >>>
                >>I'm basically asking how to create a Windows forms application with more
                >>than 1 form. :) All the examples on the internet of this type of
                >>programming typically show one form.
                >>>
                >>I'm trying to understand how to create a standard UI (i.e. window size,
                >>title, menustrip, etc) and then change the content of the form based on
                >>what the user wants to do.
                >>>
                >>Thanks. :)
                >>>
                >>Scott
                >>

                Comment

                • Family Tree Mike

                  #9
                  Re: Windows Forms Question

                  Just to clarify, a panel can be a container for a form. This lets you use
                  the form as both a tradtional form and as something like a user
                  control or panel within the form. My example in this thread shows
                  how to dock a form in the panel.

                  When you dock a form in a panel, you should set the border to none,
                  and I see I forgot that in my other post.


                  "Jack Jackson" <jjackson@cinno vations.netwrot e in message
                  news:qp3ed41fhj 31i5jb58gsv2eqt 2u31av1tu@4ax.c om...
                  >A form is a window. You can display different content in a form, or
                  you can create more forms and display them. There is no concept of
                  replacing one form with another, except for MIDI child windows where
                  you show one or more child windows in a containing parent window.
                  >
                  The easiest way to display different content in a form is to have two
                  or more containers (e.g. Panel) in a form, and make one visible at a
                  time.
                  >
                  On Sun, 21 Sep 2008 06:37:27 -0700, "Scott Stark"
                  <email@scottsta rk.comwrote:
                  >
                  >>Hi James,
                  >>
                  >>Sub-classing seems to be more along the lines of what I'm looking for.
                  >>I'll
                  >>look into that, but it seems that then I'll be able to make Form1 and
                  >>Form2
                  >>inherit the base controls from, say "BaseForm" and then add the required
                  >>functionali ty to Form1 and Form2.
                  >>
                  >>However, how do I get Form2 to display when the user is looking at Form1?
                  >>Form2.Show( ) would open a new window? I want to "replace" Form1 with Form2
                  >>in the same window, if that makes sense.
                  >>
                  >>"James Hahn" <jhahn@yahoo.co mwrote in message
                  >>news:OS6bvc5G JHA.1156@TK2MSF TNGP05.phx.gbl. ..
                  >>There's a good discussion here:
                  >>http://msdn.microsoft.com/en-us/libr...29(VS.71).aspx
                  >>Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET
                  >>>
                  >>However, your last paragraph seems to contradict the approach described
                  >>there - opening different forms (with different content) is one way of
                  >>allowing your user to perform different tasks. Changing the content of
                  >>the current form is a different way of allowing your user to perform
                  >>different tasks. Of course, you can use both procedures within the one
                  >>application , but they are different programming techniques.
                  >>>
                  >>If you are talking about using a form template so that you are using
                  >>different forms but with a consistency in a number of basic controls on
                  >>the form, and you don't want to be separately adding and tweaking those
                  >>repeated controls, then you are talking about subclassing the form. See
                  >>http://msdn.microsoft.com/en-us/libr...13(VS.71).aspx
                  >>Windows Forms Inheritance
                  >>>
                  >>"Scott Stark" <scott@webservi cesinc.comwrote in message
                  >>news:OrErch4G JHA.4760@TK2MSF TNGP05.phx.gbl. ..
                  >>>Hello,
                  >>>>
                  >>>I'm *just* delving into Windows forms-based programming without the
                  >>>benefit of any books, etc. I have a background in light ASP.NET work,
                  >>>so
                  >>>forgive me if this is a really basic question related to Windows GUI.
                  >>>>
                  >>>I've created a "Form1.vb" file in my project, added a menustrip, etc.
                  >>>When a user clicks on a menu item, how do I get it to show a new form
                  >>>in
                  >>>the same window?
                  >>>>
                  >>>I'm basically asking how to create a Windows forms application with
                  >>>more
                  >>>than 1 form. :) All the examples on the internet of this type of
                  >>>programmin g typically show one form.
                  >>>>
                  >>>I'm trying to understand how to create a standard UI (i.e. window size,
                  >>>title, menustrip, etc) and then change the content of the form based on
                  >>>what the user wants to do.
                  >>>>
                  >>>Thanks. :)
                  >>>>
                  >>>Scott
                  >>>

                  Comment

                  • =?Utf-8?B?a2FyaW0=?=

                    #10
                    Re: Windows Forms Question

                    Hi Scott:
                    I'm not the smartest in VB.Net, but one way if you want to replace form1
                    with form2 is when you set the button on form1 to show form2, you can also
                    set it to close form1 as well. and if you want form1 to show again when
                    closing form2, you can do the same thing. show form1 and close form2.

                    Private Sub btnShowForm2_Cl ick(ByVal sender As System.Object, ByVal e As
                    System.EventArg s) Handles Button13.Click
                    form2.show()
                    Me.Close()
                    End Sub

                    hope this helps.

                    Comment

                    Working...