Private Sub Command3_Click()
    Dim NewColor As Long
    NewColor = ShowColor
    If NewColor <> -1 Then
        Me.BackColor = NewColor
    Else
        MsgBox "You chose cancel"
    End If
End SubPrivate 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
关于取得颜色值,查到再告诉你:-)

解决方案 »

  1.   

    使用VB自带的CommonDialog控件,可以打开WINDOWS调色板对话框,并可返回你要的颜色代码
      

  2.   

    If CommonDialog1.ShowColor then
      

  3.   

    If CommonDialog1.ShowColor then
       MyColor = CommonDialog1.Color
    ENDIF
      

  4.   

    在Form上添加CommandButton、TextBox、CommonDialog以及以下代码Private Sub Command1_Click()
        
        On Error GoTo lEnd
        
        Dim lngColor As Long
        
        With CommonDialog1
            .CancelError = True
            .ShowColor
            Text1.BackColor = .Color
        End With
        
    lEnd:
        
    End Sub
      

  5.   

    索性再把api入口告诉您:
    Private Declare Function CHOOSECOLOR Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
      

  6.   

    用CommonDialogCommonDialog1.Show  '打开颜色对话框Form1.BackColor = CommonDialog1.Color  '将选择的颜色传给背景