SIGN UP MEMBER LOGIN:    
ARTICLE

ColorDialog : How to use?

Posted by Mahesh Chand Articles | C# Language December 21, 2000
Changing color of your Window and its controls is a piece of cake in C# using ColorDialog class.
Reader Level:

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;
}

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor