OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   VBA Form Color Picker? (http://forum.oberonplace.com/showthread.php?t=7478)

PAnderson 20-01-2011 19:08

VBA Form Color Picker?
 
Sigh. I am trying to figure out how to do something which you macro gurus probably can do in your sleep. I want to add buttons on my form for the user to choose a color from the Fill dialog and also the Outline dialog. Most of the ones I've seen on macro forms have a small square that is a live preview of the color and then the button to bring up the dialog just has an asterisk on it.

Is there a sample form somewhere I can pick apart and study? Would it also be possible to add and eye dropper to the form as well? Seems like it should be a simple thing to figure out, but I need pointed in the right direction.

Thank you in advance...
Patti

runflacruiser 20-01-2011 19:51

Hi.
Here's a start.
Put the top 2 subs in form's code. Create a command button called cmdGetCol
Use the bottom function in any module to retrieve the color.

-John



Code:

Option Explicit

Private Sub cmdGetCol_Click()

    Dim fillColor As New Color ' fill color
    fillColor.RGBAssign 153, 153, 153
   
    If fillColor.UserAssignEx Then
        If VersionMajor > 12 Then
            SaveSetting "Patti Macro", "Preferences", "fillColorSet", 13
            SaveSetting "Patti Macro", "Preferences", "fillColor", fillColor.ToString
        End If
   
        fillColor.ConvertToRGB
        cmdGetCol.BackColor = RGB(fillColor.RGBRed, fillColor.RGBGreen, fillColor.RGBBlue)
   
        isDark fillColor, cmdGetCol
       
    End If
   
End Sub

Private Function isDark(col As Color, cmdBut As CommandButton) As Boolean
    On Error Resume Next
    isDark = False
    col.ConvertToLab

    If col.LabLuminance < 75 Then
        isDark = True
    End If
   
    If isDark Then
        cmdBut.ForeColor = RGB(255, 255, 255)
    End If
   
End Function

Public Function getCol() As Color
    Set getCol = New Color
    Dim colSet As String, regCol As String
   
    On Error GoTo errorAssignDefaultCol
   
    getCol.RGBAssign 153, 153, 153
    colSet = GetSetting("Patti Macro", "Preferences", "fillColorSet", 0)
    regCol = GetSetting("Patti Macro", "Preferences", "fillColor")

       
    If colSet = 13 Then
        getCol.StringAssign regCol
    End If
   
Exit Function
errorAssignDefaultCol:
    getCol.RGBAssign 153, 153, 153
   
End Function



All times are GMT -5. The time now is 04:21.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com