How to transfer parameters between interfaces?

Hi,

I am using Visual Studio 2005 and VB.net to compile a program.

I have two interfaces: interface A and B. On interface A, there is a button, and after I click this button, interface B appears. When interface B appears, a parameter in A will be transfer to B. Then I close B, and another parameter in B will be transferred to A. The second parameter might be a text string or an integer, and after B is closed, this text string will replace the original text on interface. How can I do that Any helpful sample example or any hyperlinks

Thanks a lot.




Answer this question

How to transfer parameters between interfaces?

  • Craig Mackles

    Lets try and get things straight here as terminology is critical - when you are referring to interface are you in fact referring to a form (or user interface)

    Basically what you trying to do is establish a two way communication to transfer properties from A to B and also a different property from B to A.

     So in the following example I will pass different variable between two forms.     Form1 has a property Foobar and Form2 has a property called bar.    The form1 passed the textbox contents to form2 bar property - which ultimately passes its textbox contents back to form1foobar property.

    The module1has two public variables which are used to keep references to each form.

    Public Class Form1
        Private _FooBar As String
        Public Property FooBar() As String
            Get
                Return _FooBar
            End Get
            Set(ByVal value As String)
                _FooBar = value
            End Set
        End Property


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            '//Create a form2 object and pass form1.textbox1 text to form2
            Dim frm2 As New Form2
            frm2.Bar = TextBox1.Text
            frm2.ShowDialog()

            Me.TextBox1.Text = Me.FooBar
        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Module1.Form1Ref = Me  '//Set Form1 reference
            TextBox1.Text = "TEST"

        End Sub
    End Class

    Public Class Form2
        Private _Bar As String
        Public Property Bar() As String
            Get
                Return _Bar
            End Get
            Set(ByVal value As String)
                _Bar = value
            End Set
        End Property


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Module1.Form2Ref IsNot Nothing Then
                Module1.Form1Ref.FooBar = TextBox1.Text  '//Set Form1 property Foobar as form2 textbox1 text property
            End If
            Me.Close()
        End Sub

        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Module1.Form2Ref = Me
            Me.TextBox1.Text = Me.Bar
        End Sub
    End Class

     

    Public Module Module1
        Public Form1Ref As Form1
        Public Form2Ref As Form2

    End Module


  • Zolt

    Thanks a lot. It is great.

  • How to transfer parameters between interfaces?