Well, I have a main form (Form1) and a second form (Form2) which is a preference box. Anyways, I made a combobox and a button on the second form, and a button on the first form which opens up the new one. Everything works well until you try to use the combo box to change the client size, this worked before when it wasn't on a new form, so I know it's meant to be working.

Here is my code:

private void button1_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            if (comboBox1.Text == "800x600")
            {
                f1.ClientSize = new System.Drawing.Size(800, 600);
            }
            if (comboBox1.Text == "300x300")
            {
                f1.ClientSize = new System.Drawing.Size(300, 300);
            }
        }

Thanks.

IF you want to affect the first form, why would you create a new instance of it? What you need to do is pass THE instance of the first from to the second form. then act upon that instance, easy.

//this is form1's button click to open preference from 2

private void prefferencesbtn_click(object sender, EventArgs e)
{
      Form2 prefs = new Form2(this); //the secret!
      prefs.Show();
}

//now the form2 needs to catch this instance and hold it.

Form MainForm;//create class var to hold form1 instance.
//constructor for form2
Public void Form2(Form mForm)
{
     //catch the instance
    MainForm = mForm;
}

//now your code

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "800x600")
            {
                MainForm.ClientSize = new System.Drawing.Size(800, 600);
            }
            if (comboBox1.Text == "300x300")
            {
               MainForm.ClientSize = new System.Drawing.Size(300, 300);
            }
        }

Happy Coding!

Great! Worked perfectly! Thank you very much!

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.