|
|
|
VB Common dialog box control does not support adding custom color programatically at runtime. You have to use ChooseColor API to get this functionality. Here is the example
Step-By-Step Example
- Create a standard exe project - Add one commandbutton - Add the following code in form1 |
Click here to copy the following block | Private Declare Function ChooseColor Lib "comdlg32.dll" _ Alias "ChooseColorA" _ (lpChooseColor As udtCHOOSECOLOR) As Long
Private Type udtCHOOSECOLOR lStructSize As Long hwndOwner As Long hInstance As Long rgbResult As Long lpCustColors As String flags As Long lCustData As Long lpfnHook As Long lpTemplateName As String End Type
Public Function GetColor() As Long Dim rc As Long Dim pChooseColor As udtCHOOSECOLOR
Dim CustomColors(63) As Byte
CustomColors(0) = 110 CustomColors(1) = 34 CustomColors(2) = 255 CustomColors(3) = 0
CustomColors(4) = 230 CustomColors(5) = 255 CustomColors(6) = 10 CustomColors(7) = 0
With pChooseColor .hwndOwner = 0 .hInstance = App.hInstance .lpCustColors = StrConv(CustomColors, vbUnicode) .flags = 0 .lStructSize = Len(pChooseColor) End With
rc = ChooseColor(pChooseColor)
If rc Then GetColor = pChooseColor.rgbResult End If
End Function
Private Sub Command1_Click() Me.BackColor = GetColor End Sub |
- Press F5 to run the project |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|