Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Color Dialog Component (control) in C# .net 2.0

Author: Zunnair
Download Source Code : 815_Color Dialog Component.zip

In this simple article you will learn that how to use Color Dialog Component

 Color dialog control is used to change back and fore color of other controls (buttons, labels, textbox, etc) on run time.

 Create new c# project. Drag Label, color dialog, and one button on the windows form.

Now write the following code on Load Form event:

C#

private void LoadForm_Color(object sender, EventArgs e)

        {

            this.Text = "DevAsp Color Dialog Application";

            lblChange.Text = "www.devasp.net";

            lblChange.ForeColor = Color.Coral;

            lblChange.BackColor = Color.Black;

        }

VB

Private Sub LoadForm_Color(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DevAsp Color Dialog Application"

        lblChange.Text = "www.devasp.net"

        lblChange.ForeColor = Color.Coral

        lblChange.BackColor = Color.Black

    End Sub

Now write the following code on button click event:

Changing fore color (First Button)

C#

private void btnChangeColor_Click(object sender, EventArgs e)

        {

            DialogResult dResult =  clrDlg.ShowDialog();

 

            if (dResult == DialogResult.OK)

            {

                lblChange.ForeColor = clrDlg.Color;  

            }

        }

VB

Private Sub btnChangeColor_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim dResult As DialogResult = clrDlg.ShowDialog()

        If dResult = DialogResult.OK Then

            lblChange.ForeColor = clrDlg.Color

        End If

    End Sub

Changing backGround color: (Second Button)

C#

private void btn_changeBackColor_Click(object sender, EventArgs e)

        {

            DialogResult dResult = clrDlg.ShowDialog();

 

            if (dResult == DialogResult.OK)

            {             

                lblChange.BackColor = clrDlg.Color;

            }

           

        }

VB

Private Sub btn_changeBackColor_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim dResult As DialogResult = clrDlg.ShowDialog()

        If dResult = DialogResult.OK Then

            lblChange.BackColor = clrDlg.Color

        End If

    End Sub

 

When user will press change color button color window willl open.

 

We are using DialogResult because we have to see what  user pressed. If user press ok than our program should apply changes but if user perss cancle than our program should do nothing.

 

This is the simple code for using Color Dialog Component (control).

Article Comments
Can anyone tell me how to custom define the set of custom colors in the color dialog box, so that when it opens those colors appear? For example, I want the first color to be pine green (0,91,68) and the second one cold (173,91,0), etc... When I define the CustcomColors array all I get is black.

Posted on 12/22/2009 9:29:39 AM by Bob Thompson

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to use web browser control in .net 2.0. (Part1)

Disclaimer - Privacy
© 2002-2017 DevASP.net