Skip to content

How to access control properties on other form? (Windows Mobile)

GUMA

Asked Apr 18, 2007, 11:56 AM EDT1 answer
Share
LinkedInX
Hi, I want to change the Text of a textbox which on other form.
I have tried the code below but it doesnt work.

On Form1:
Form f2 = new Form2();
f2.TextBox1.Text = "testing";

I cant get access to the controls on Form2. Why doesnt this work?

Note: Its a windows mobile application.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    My guess is you'd want to wait until Form2 is loaded before its controls are available (not null) to be able to change their properties, and that usually happens after the Form_Load event, which doesn't take place until you show the form (ShowDialog or SHow)

    I think your best bet is to define a public property on Form2, say:

    public string strTextBoxText;

    then change your code to do the following:

    Form2 form2=new Form2();
    form2.strTextBoxText="The new Text";
    form2.Show();

    Then catch the Load Event for Form2, and inside it implement the following:

    Form2_Load(...)
    {
       TextBox.Text=strTextBoxText;
    }

    Hope this helps

    0