Setting color of controls was not an easy task in VC++. In C#, setting colors of controls is piece of cake. The ColorDialog class does everything for you. The ColorDialog is derived from common dialog. ShowDialog displays color dialog and let you pick a color. Color property of the ColorDialog returns the current selected color.In this sample example, I have two buttons. Foreground Color button sets foreground color of all controls while Background Color sets the background color of all the controls. Here is the corresponding code:protected void button2_Click (object sender, System.EventArgs e){ColorDialog colorDlg = new ColorDialog();colorDlg.ShowDialog();textBox1.BackColor = colorDlg.Color;listBox1.BackColor = colorDlg.Color;btn.BackColor = colorDlg.Color;} protected void button1_Click (object sender, System.EventArgs e){ColorDialog colorDlg = new ColorDialog();colorDlg.ShowDialog();textBox1.ForeColor = colorDlg.Color;listBox1.ForeColor = colorDlg.Color;btn.ForeColor = colorDlg.Color;}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: