Title | Use the color selection dialog with custom colors in VB .NET |
Keywords | color, select color, pick color, color selection, color selection dialog, VB.NET |
Categories | Graphics, 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
|