ColorDialog in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the ColorDialog control


ColorDialog

Visual Basic offers a wide range of dialog boxes that allow the user to make standard selections and each of them has a very specific purpose.
The purpose of the ColorDialog is selecting a color.

This component displays a dialog that enables the user to select a color from a standard palette or from a custom color palette.

First you call its ShowDialog method to display a color selection dialog and then check if ShowDialog returns OK or Cancel if the user cancels.

The following code sets the dialog box's Color property to the background color of the CheckedListBox control. Meaning, it displays the dialog box and, if the user clicks OK, it sets the StatesList background color according to user's selection.

    Private Sub ChangeColor_Click(sender As Object, e As EventArgs) Handles ChangeColor.Click
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            StatesList.BackColor = ColorDialog1.Color
        End If
    End Sub


example

Previous Lesson | Next Lesson


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.