How to use the controls from another form in form I working in.

I have problem, I was using the Visal Basic, and now have to migrate to the C#. Its not a problem. But in first steps with C# I have found a few diferences from VB. One I cant solve. For example in Form1 I have a TextBox1 and a Button1. I enter in TextBox1 "sviec", and click the Button1. Then opens the Form2 with Label1 on it and label says "sviec". In VB the Form2 code looks like this:

Public Class Form2

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.Label1.Text = Form1.TextBox1.Text

End Sub

End Class

So how I can translate this Me.Label1.Text = Form1.TextBox1.Text from VB to C#

Thank You!



Answer this question

How to use the controls from another form in form I working in.

  • Giminiani

    Yes thx its working. Now I will try it in my real programm, and will report.
  • rgny

    It aint working, I allredy tride. When I Write this.Label1.Text = Form1. and now in list I cant find any control that is on the Form1.

  • TalhaAziz

    If that method is an event handler for the onload of form1 then you can do it like this:

    Form1 form = sender as Form1;
    if(form != null)
    this.Label1.Text = form.TextBox1.Text;


  • MJA73

    Hi,
    here's your answer:

    this.Label1.Text = Form1.TextBox1.Text;


  • fremontca

    Yes everything is going. Thank you guys.
  • pkv

    On Form1 change textbox Modifiers property to Public. Then it will work.

  • Winter Grave

    Aint working - Error 1 An object reference is required for the nonstatic field, method, or property 'CSpalidziba.Form1.textBox1'

    And in the list ther still is no textBox1


  • How to use the controls from another form in form I working in.