471,326 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

How to change control properties in Form1 from Form2

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
Dec 13 '05 #1
3 2380
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
Mateusz Rajca wrote:
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


Dec 13 '05 #2
Thanks! Ill try it

"RvGrah" wrote:
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
Mateusz Rajca wrote:
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


Dec 13 '05 #3
What code should I add so I can change the default homepage for my web
browser in a preferences dialog?

"RvGrah" wrote:
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
Mateusz Rajca wrote:
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


Dec 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Doug | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.