Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleUse the color selection dialog with custom colors in VB .NET
Keywordscolor, select color, pick color, color selection, color selection dialog, VB.NET
CategoriesGraphics, VB.NET, Software Engineering
 
To initialize the custom colors, create an integer array containing the color values in &HBBGGRR format. Assign this array to the ColorDialog control's CustomColors property.

This example also sets the control's FullOpen property to True so the dialog displays with its custom color area displayed.

To use the dialog, set its Color property to the color you want it to have initially selected. Then call the control's ShowDialog method. If the method returns DialogResult.OK, do something with the color that the user selected.

 
Private Sub Form1_Load(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles MyBase.Load
    ' Initialize the color dialog's custom colors.
    Dim colors() As Integer = { _
          &HFF, &H11FF, &H22FF, &H33FF, _
        &H44FF, &H55FF, &H66FF, &H77FF, _
        &H88FF, &H99FF, &HAAFF, &HBBFF, _
        &HCCFF, &HDDFF, &HEEFF, &HFFFF}
    dlgColor.CustomColors = colors

    ' Make the dialog open with the custom
    ' colors displayed.
    dlgColor.FullOpen = True
End Sub

Private Sub btnPickColor_Click(ByVal sender As _
    System.Object, _
 ByVal e As System.EventArgs) Handles btnPickColor.Click
    dlgColor.Color = Me.BackColor
    If dlgColor.ShowDialog() = DialogResult.OK Then
        btnPickColor.BackColor = dlgColor.Color
        Me.BackColor = dlgColor.Color
    End If
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated