-3

I am trying to pass a text value from a settings form to another form. What I am trying to do is pass a string value form a textbox on the settings form to the main form. The main form has a GunaUI2 Button (Which I am trying to control)

I was trying to use public Form1 frmMain = new Form1(); to import my main form to my settings form. Then I would try to change the text of the GunaUI2 Button with this code: frmMain.btn_1.Text = textBox1.Text;

Any help would be greatly appreciated, Thanks EB

1 Answers1

0

The easiest way to pass any value from a form to another form is by creating a second constructor to the form you want to pass the value to. For Example:

Let's say you want to pass string from form1 to form2 then the code would look something like this:

First create a second constructor in form2 like:

public Form2(string s)
        {
            InitializeComponent();
            String_passed_from_Form_1 = s
        }

Then when you make the object of form2 in form1 code:

Form2 obj = new Form2("String Value to pass to form2");
obj.show();

Doing the above the string value will be stored in the vairable "String_passed_from_Form_1" and would be accessable in the other form.