How to change control properties in Form1 from Form2

G

Guest

Hello,

I have Form1 - the main form with some controls including a button.

I have Form2 - the properties form with a combobox and button. The user can
select the colors of a button in the combobox in Form2 and press "OK". What
code should I add to "OK" so that the user can change the colors of a button
in Form1?

Mateusz
 
R

RvGrah

Public variables must be created in the receiving form, such as:
In Form1:
public Color col;

then this variable can be called and written to.

The form(s) also need a definitive reference to one another. Not to
just the class such as Form1.xxx, but to the specific instance of the
form in question, such as:

In Form1:
Form2 myKid = new Form2;
myKid.myDad = this;
myKid.Show();


In Form2:
public Form1 myDad;

then you can write code in Form2 such as:
myDad.col = Color.FromARGB(206, 206, 244);


This code is not tested and is informational, but should be enough to
get you going.

Bob
 
G

Guest

Thanks! Ill try it

RvGrah said:
Public variables must be created in the receiving form, such as:
In Form1:
public Color col;

then this variable can be called and written to.

The form(s) also need a definitive reference to one another. Not to
just the class such as Form1.xxx, but to the specific instance of the
form in question, such as:

In Form1:
Form2 myKid = new Form2;
myKid.myDad = this;
myKid.Show();


In Form2:
public Form1 myDad;

then you can write code in Form2 such as:
myDad.col = Color.FromARGB(206, 206, 244);


This code is not tested and is informational, but should be enough to
get you going.

Bob
 
G

Guest

What code should I add so I can change the default homepage for my web
browser in a preferences dialog?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top