I want to change form1 textbox1 text from from2 variable.
This is the flow.

  1. Show form1
  2. click button in form1
  3. then show form2 (form1 do not hide. It is still visible)
  4. click button in form2 (form2 has variable and it set to form1 text box and hide form2)

(In my system form1 is always show)

This is my code in form1 for access textbox from other form

    //FIRST CODE BLOCK
    public string textRoomID
    {
        get
        {
            return this.txt_RoomID.Text;
        }
        set
        {
            this.txt_RoomID.Text = value;

        }
    }

This is the code of form2 button click

//SECOND CODE BLOCK
form1 obj_f1 = new form1(); //create the object of 
obj_f1.textRoomID = RoomID; //Assign variable
this.Hide();

When I debugging the code set method is working well and it is not showing any error.
But not update my text box.

if I use this flow, above code worked.

  1. form2 show
  2. form2 button click (SECOND CODE BLOCK execute and additionaly added form1.show();)

But my requirment is first i mensioned flow.
How to do my work? Why it is not assigning value to text box?

Recommended Answers

All 4 Replies

You are assigning a variable (RoomID) to a string property (textRoomID) of the obj_f1 form. Guess you must assign it to the Text property of a TextBox in the Form.

Thanks for your reply ddanbe.
You mean like this code?????

obj_f1.txt_RoomID.Text = RoomID;

This error shows
'form1.txt_RoomID' is inaccessible due to its protection level

You must add the public access modifier before the definition of RoomID.
Like: public string RoomID = string.Empty;

I've got an artical.
Link

This helps me a lot. I post this for begginers like me for imroving thereselves.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.