Anyway to use the Colour Dialog Selector with out a control?
Printable View
Anyway to use the Colour Dialog Selector with out a control?
Yes
VB Code:
Private Type CHOOSECOLOR 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 Private Declare Function CHOOSECOLOR Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long Private Function ShowColor() As Long Dim cc As CHOOSECOLOR Dim Custcolor(16) As Long Dim lReturn As Long 'set the structure size cc.lStructSize = Len(cc) 'Set the owner cc.hwndOwner = Me.hWnd 'set the application's instance cc.hInstance = App.hInstance 'set the custom colors (converted to Unicode) cc.lpCustColors = StrConv(CustomColors, vbUnicode) 'no extra flags cc.flags = 0 'Show the 'Select Color'-dialog If CHOOSECOLOR(cc) <> 0 Then ShowColor = cc.rgbResult CustomColors = StrConv(cc.lpCustColors, vbFromUnicode) Else ShowColor = -1 End If End Function Private Sub Command1_Click() Dim NewColor As Long NewColor = ShowColor If NewColor <> -1 Then Me.BackColor = NewColor Else MsgBox "You chose cancel" End If End Sub
This code generating me an error. Can anybody help?
What error is it generating and on what line?
He forgot to include something. Add the following lines to the ShowColor FunctionVB Code:
Dim CustomColors() As Byte ReDim CustomColors(0 To 16 * 4 - 1) As Byte
It writes me: "Invalid use of Me keyword". I am using visual basic editor 6.3. The "Me" is used in .Net?Quote:
Originally Posted by Hack
I also do not understand what should this macro do.
Boris
Make sure all the code is in the form and not a module.
I have created an userform and commandbutton. The code is inside this userform. Now writes me an error: "Method or data member not found" at the line:Quote:
Originally Posted by moeur
cc.hwndOwner = Me.hwnd
I have tryed to write me. again, but VB is not offering me hwnd.
If your form is called "Form1" then try Form1.hWnd
I have changed Me to Userform2, but it still do not offering me hwndQuote:
Originally Posted by moeur
Quote:
Originally Posted by moeur
I have changed:
cc.hwndOwner = Useform1.Hwnd
to
cc.hwndOwner = Application.Hwnd
and
cc.hInstance = App.hInstance
to
cc.hInstance = Application.hInstance
Now it works. When I click commandbutton a color definition form is opened.
My intention was to place the rainbow rectangle (I do not know the official name) inside my own userform.
Can anybody help.
Are you attempting to do this in VB6 or VBA?Quote:
Originally Posted by bolcskei
Please red my last quote. I would like to make an add-ins in Excel and I am using Visual Basic Editor, version 6.3.Quote:
Originally Posted by Hack
When you say "Visual Basic Editor" it's a bit ambigious. The actual language you are using is VBA and it is not the same as VB6 the desktop production language. VBA has more limitations, one of which you have probably just found.
I do not dispute with you. I am not very experienced in VB. I have started to use it approximately a year before.Quote:
Originally Posted by penagate