Windows Phone Developers

Tuesday, April 21, 2009

How to Disable Custom Colors in ColorDialog using C# (.NET)

How to restrict the user to pre-defined colors in C# ColorDialog

With .NET’s ColorDialog one can select the pre-defined as well as the custom colors. For some reason, if you want only the pre-defined colors to be selected. Set the AllowFullOpen to false.

private void btnSelectColor_Click(object sender, EventArgs e)

{

colorDialog1.AllowFullOpen = false;

colorDialog1.ShowDialog();

this.BackColor = colorDialog1.Color;

}


ColorDialog with custom colors
Restricted ColorDialog

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

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