I just use the Common Dialog Control to change the colors. I click on a label to change it's color, and save them to a file. When I load the program, it reads the file and loads the label colors. I also put the CDC control on a small form, and can move the location of the form before I show it.
Here is how to use the CDC control. I added the Show Color today.
EDIT: After 66 views, I'm updating to version 6 that asks if you want to overwrite in a save operation.
Last edited by dglienna; Jan 31st, 2006 at 01:01 PM.
Change the lpCustColors member to a Long instead of a string and set it to VarPtr(CustColors(0)) instead of using StrConv. You can then store these values somewhere and load them before the call.
OK. I've made some slight changes to your code. I've changed the structure to use a Long for the lpCustColor member. I've also changed your CustomColors() array to be of the type Long instead of Byte. I removed the local Custcolor() array you had in the Command1_Click event since that doesn't do anything. Instead I use the CustomColors() array.
The changes are in bold below.
VB Code:
Private Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors[b] As Long [/b]
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function ChooseColorAPI Lib "comdlg32.dll" Alias _
"ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
Private CustomColors()[b] As Long [/b]
Private Sub Form_Load()
[b] ReDim CustomColors(15) As Long 'index 0 to 15 = 16 colors [/b]
Dim i As Integer
For i = LBound(CustomColors) To UBound(CustomColors)
CustomColors(i) = 0
Next i
End Sub
Private Sub Command1_Click()
Dim cc As CHOOSECOLOR
Dim lReturn As Long
cc.lStructSize = Len(cc)
cc.hwndOwner = Me.hWnd
cc.hInstance = 0
cc.lpCustColors =[b] VarPtr(CustomColors(0)) [/b]
cc.flags = 0
lReturn = ChooseColorAPI(cc)
If lReturn <> 0 Then
Text1.Text = cc.rgbResult
Label1.ForeColor = cc.rgbResult
[b] 'The CustomColors() array now contains all the custom colors
'that the user has selected. You can save this array values
'to a file if you want and reload them in Form_Load.
'Next time you click this button these values are used again! [/b]
That's the answer! Thanks a lot
Joacim. I don't know where my heads been today...I've had that brain fog
all day. I'll be sure and give you an excellent rating! Thanks again and have
a good one.