Windows Develop Bookmark and Share   
 index > Windows Forms General > How to change control properties in Form1 from Form2?
 

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
Mateusz Rajca  Monday, December 12, 2005 11:13 PM
Form2 should expose a property that gives you the color selected, then if the user pressed OK, Form1 should read this and set the color of the buttons with it.

I hope your forms are not named Form1 and Form2 :-)
cgraus  Monday, December 12, 2005 11:45 PM
Form2 should expose a property that gives you the color selected, then if the user pressed OK, Form1 should read this and set the color of the buttons with it.

I hope your forms are not named Form1 and Form2 :-)
cgraus  Monday, December 12, 2005 11:45 PM
Can you please explain more on how to do it. I am just a C# beginner.
Mateusz Rajca  Tuesday, December 13, 2005 12:28 AM
In Form2:


public Color NewColor
{
  get { return _newColor; }
}

private Color _newColor;

This variable is set within the dialog, by the end user selecting a color.  Actually, there's a color dialog built in to Windows, are you using that, or how is a color being selected ?

In Form1

Form2 dlg = new Form2;

if (DialogResult.OK == dlg.ShowDialog())
{
   this.theButton.BackColor = dlg.NewColor;
}

I'm going from memory, the property may not be called BackColor, but that's the general idea.
cgraus  Tuesday, December 13, 2005 12:32 AM

You can use google to search for other answers

Custom Search

More Threads

• renaming a picture to a file
• Bitmap.MakeTransparent() throws Out of Memory Error()
• How to access a standard Control's HelpProvider extended attributes?
• Clipboard structure
• combobox c# text add ... simple question
• Change cursor from Cursors.WaitCursor
• Windows Form operation under different screen resolutions
• Canceling the closing event on a win form
• Why do my treeview tooltips flicker?
• Opening Notepad and dumping text into it