Closing Winforms

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

    Closing Winforms

    Hi all,

    I am running into an issue trying to close a form from another form.

    I have a main form called MainForm.

    A child form is opened in the MainForm as follows:
    Dim Form2 As New Form2
    Form2.MdiParent = Me
    Form2.Show()

    Now from Form2 I am opening another form as follows:
    Dim Form3 As New Form3
    Form3.MdiParent = Me.MdiParent
    Form3.Show()

    Form3 has 1 button that when pressed I want it to close Form2.
    Form3 has another button when pressed I want it to return the focus to form2.

    Don't know why I am having problems with this, doesn't seem like a
    compicated thing to do. Any ideas?

    Thanks in advance.

    --
    Kevin
  • ksedran

    #2
    RE: Closing Winforms

    I forgot to put another question in my original post.

    I was wondering if there was a way to access functions on form2 from form3.

    For example, when a button is clicked on form3, some action is performed on
    form2, like a datagrid refresh for instance.

    Thanks again.



    "ksedran" wrote:
    [color=blue]
    > Hi all,
    >
    > I am running into an issue trying to close a form from another form.
    >
    > I have a main form called MainForm.
    >
    > A child form is opened in the MainForm as follows:
    > Dim Form2 As New Form2
    > Form2.MdiParent = Me
    > Form2.Show()
    >
    > Now from Form2 I am opening another form as follows:
    > Dim Form3 As New Form3
    > Form3.MdiParent = Me.MdiParent
    > Form3.Show()
    >
    > Form3 has 1 button that when pressed I want it to close Form2.
    > Form3 has another button when pressed I want it to return the focus to form2.
    >
    > Don't know why I am having problems with this, doesn't seem like a
    > compicated thing to do. Any ideas?
    >
    > Thanks in advance.
    >
    > --
    > Kevin[/color]

    Comment

    • [Alan Flores]

      #3
      RE: Closing Winforms

      create a holder class

      public class AllForms

      public Form1 as form1
      public Form2 as form2

      End class

      put this code on each of the form :

      private Forms as AllForms

      now when you try to create the form add one more line..

      Dim 2ndForm As New Form2
      2ndForm.MdiPare nt = Me
      Forms.Form2 = 2ndForm
      2ndForm.Show()

      you can Forms.Form2.Clo se()
      so you can access Forms.Form2.Met hodInForm2

      do the same in form 1..


      "ksedran" wrote:
      [color=blue]
      > I forgot to put another question in my original post.
      >
      > I was wondering if there was a way to access functions on form2 from form3.
      >
      > For example, when a button is clicked on form3, some action is performed on
      > form2, like a datagrid refresh for instance.
      >
      > Thanks again.
      >
      >
      >
      > "ksedran" wrote:
      >[color=green]
      > > Hi all,
      > >
      > > I am running into an issue trying to close a form from another form.
      > >
      > > I have a main form called MainForm.
      > >
      > > A child form is opened in the MainForm as follows:
      > > Dim Form2 As New Form2
      > > Form2.MdiParent = Me
      > > Form2.Show()
      > >
      > > Now from Form2 I am opening another form as follows:
      > > Dim Form3 As New Form3
      > > Form3.MdiParent = Me.MdiParent
      > > Form3.Show()
      > >
      > > Form3 has 1 button that when pressed I want it to close Form2.
      > > Form3 has another button when pressed I want it to return the focus to form2.
      > >
      > > Don't know why I am having problems with this, doesn't seem like a
      > > compicated thing to do. Any ideas?
      > >
      > > Thanks in advance.
      > >
      > > --
      > > Kevin[/color][/color]

      Comment

      • ksedran

        #4
        RE: Closing Winforms

        Thanks Alan, that worked great!!


        "[Alan Flores]" wrote:
        [color=blue]
        > create a holder class
        >
        > public class AllForms
        >
        > public Form1 as form1
        > public Form2 as form2
        >
        > End class
        >
        > put this code on each of the form :
        >
        > private Forms as AllForms
        >
        > now when you try to create the form add one more line..
        >
        > Dim 2ndForm As New Form2
        > 2ndForm.MdiPare nt = Me
        > Forms.Form2 = 2ndForm
        > 2ndForm.Show()
        >
        > you can Forms.Form2.Clo se()
        > so you can access Forms.Form2.Met hodInForm2
        >
        > do the same in form 1..
        >
        >
        > "ksedran" wrote:
        >[color=green]
        > > I forgot to put another question in my original post.
        > >
        > > I was wondering if there was a way to access functions on form2 from form3.
        > >
        > > For example, when a button is clicked on form3, some action is performed on
        > > form2, like a datagrid refresh for instance.
        > >
        > > Thanks again.
        > >
        > >
        > >
        > > "ksedran" wrote:
        > >[color=darkred]
        > > > Hi all,
        > > >
        > > > I am running into an issue trying to close a form from another form.
        > > >
        > > > I have a main form called MainForm.
        > > >
        > > > A child form is opened in the MainForm as follows:
        > > > Dim Form2 As New Form2
        > > > Form2.MdiParent = Me
        > > > Form2.Show()
        > > >
        > > > Now from Form2 I am opening another form as follows:
        > > > Dim Form3 As New Form3
        > > > Form3.MdiParent = Me.MdiParent
        > > > Form3.Show()
        > > >
        > > > Form3 has 1 button that when pressed I want it to close Form2.
        > > > Form3 has another button when pressed I want it to return the focus to form2.
        > > >
        > > > Don't know why I am having problems with this, doesn't seem like a
        > > > compicated thing to do. Any ideas?
        > > >
        > > > Thanks in advance.
        > > >
        > > > --
        > > > Kevin[/color][/color][/color]

        Comment

        Working...