CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    3

    Navigating between multiple forms in C#

    Hi,

    I have been looking for an example on the web to reference a form within another form so that the properties can be used in the 2nd form. I have found a VB example (unfortunately i know nothing about VB) below but i have not been able to find a c# example.


    The VB code in question is: -


    Code:
    Dim myForm As Form2
    Private Sub Button1_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles Button1.Click
      If myForm Is Nothing Then
        myForm = New Form2
        myForm.myCaller = Me
      End If
      myForm.Show()
    End Sub
    I have a form that opens another form. The 2nd form then opens a 3rd form form etc. I need to be able to reference the first form within the 2nd form so that if i click on a back button it hides the 2nd form and re-opens the 1st form and then if i click next on the 1st form i need to be able to re-open the 2nd form.

    Can anyone please help me?

    Thanks.

    Darren

  2. #2
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225

    Re: Navigating between multiple forms in C#

    You could use the overloaded Show method for the Form object and pass "this" as owner, then you can find out with the second forms Owner property.

    In form1:
    Code:
    Form2 f = new Form2();
    f.Show(this);
    In form2:
    Code:
    MessageBox.Show(this.Owner.ToString());
    Maybe not the best way, but a way.

    /Leyan
    Last edited by Athley; March 10th, 2006 at 04:55 PM.

  3. #3
    Join Date
    Jul 2002
    Location
    India
    Posts
    505

    Re: Navigating between multiple forms in C#


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured