Windows Phone Developers

Friday, April 17, 2009

How to use ColorDialog in C# (.NET)

Allow user to customize form background color using ColorDialog

The Windows Forms ColorDialog component is a pre-configured dialog box that allows the user to select a color from a palette and to add custom colors to that palette. It is the same dialog box that you see in other Windows-based applications to select colors. Use it within your Windows-based application as a simple solution in lieu of configuring your own dialog box.

To add the dialog to Windows Form select the ColorDialog from the tool box





The component will be dropped in the component-tray below the form


Use the following code to show the dialog and set the selected color as the background of the form

private void btnSelectColor_Click(object sender, EventArgs e)

{

colorDialog1.ShowDialog();

this.BackColor = colorDialog1.Color;

}



The form will be set as shown below




Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

3 comments:

  1. Seriously...
    why did you write this article?

    ReplyDelete
  2. how to add color dialog box in c# web applications?

    ReplyDelete