Get value from child to parent window
-
Hi, In my application i have to open a new window and then to do some calculation and then to show that value on parent window. thanks in advance
-
Hi, In my application i have to open a new window and then to do some calculation and then to show that value on parent window. thanks in advance
Hello, You can try the given solution. Lets say we have two forms Form1 and Form2. In form2 we define a function which takes the Form1 as argument. Form1 _frm;
Public Sub ShowForm(ByVal frm As Form1, ByVal img As Image) _frm = frm Me.Show() End Sub
Lets say we will return a value of type integer to Form1. For that we will have to define an integer variable in Form1 and a Property for that variable to set its value.Dim _val As Integer Property Val() As Integer Get Return _val End Get Set(ByVal value As Integer) _val = value End Set End Property
On Button Click in Form 1 we will open the Form2 in the following manner:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As New Form2 frm.ShowForm(Me) End Sub
Now in FormClosing of Form2, we will set the value.Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing _frm.Val = 2 End Sub
I hope this helps. Regards, AllenAllen Smith ComponentOne LLC www.componentone.com