Getting value from one form to another in Windows Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have 3 forms in my application. Form1 which is a MDI form calling Form2 & Form3. Form2 has a textbox "TextBox1" and Form3 has a CommandButton "Button1".

I will show both Form1 & Form2 as MDI Child from Form1. Now when i click on the Button1 in Form3, I want to access the TextBox1 value of Form2.

How to achieve this... in VB6 is was very simple as I can use Form2.TextBox1 but how in VB.Net or C#

Thanks...

Pradeep
 
Hi Pradeel,

Have a look at the me.parentform from your form.

http://msdn.microsoft.com/library/d...formscontainercontrolclassparentformtopic.asp

When you have that, you can again get the childforms of that form.

I hope this help?

Cor

Hi,
I have 3 forms in my application. Form1 which is a MDI form calling Form2
& Form3. Form2 has a textbox "TextBox1" and Form3 has a CommandButton
"Button1".
I will show both Form1 & Form2 as MDI Child from Form1. Now when i click
on the Button1 in Form3, I want to access the TextBox1 value of Form2.
How to achieve this... in VB6 is was very simple as I can use
Form2.TextBox1 but how in VB.Net or C#
 
Hi,

In this case my MDI form is not doing anything other than just calling the Form2 & Form3.

I need to get the data of Form2 from Form3 where both are MDI Childs.

Thanks

Pradeep
 
Did you try it?
In this case my MDI form is not doing anything other than just calling the Form2 & Form3.

I need to get the data of Form2 from Form3 where both are MDI Childs.

Thanks

Pradeep
 
Hi PradeepKel,

As I asked before did you try it, by instance this in form3?
\\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
For Each frm As Form In _
Me.ParentForm.MdiChildren()
If frm.Name = "Form2" Then
TextBox1.Text = DirectCast(frm, Form2).TextBox1.Text
End If
Next
End Sub
///

I hope this fullfils your needs, I tested it and it did go.
(You can of course as well create a shared property to use, however this is
a direct anwer in my opinion on your question)

Cor
"
 
Hi cor,

Thanks a lot... it works fine...

Just to know... how to handle the situation if the MDI form is not available.

Regards

Pradeep
 
Back
Top