Results 1 to 22 of 22

Thread: [VB6] Wheel Color Picker

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    [VB6] Wheel Color Picker

    Note: this project is no longer maintained/updated and has been superseded by ColorDialog.


    This is a replacement of the standard color dialog. It does more or less the same function but with some different features. The most noticeable difference is that it presents a wheel instead of a rectangle for choosing the colors.

    The dialog box can work using HSV or HSL color systems.

    Name:  WheelColorPicker_scr1.png
Views: 5386
Size:  118.0 KB

    The interface is through a class module named ColorDialog.

    The dialog is customizable, the properties are:

    ColorSystem:
    Allows to switch between HSV and HSL color systems.
    The colors of the wheel differ between systems, and also the value of the parameters and their full scales.
    The default is HSV.

    DialogTitle:
    The title for the dialog that will be displayed on the window caption.
    If not set, the default is "Color Picker".

    DialogSizeBig:
    If True, the wheel and the dialog will be bigger.
    The default is False.

    RecentColorsVisible:
    If False, the recent colors are not displayed.
    The default is True.

    ColorParametersVisible:
    If False, the controls to see or sets the color parameters such as RGB, HLS are not displayed.
    The default is True.

    HexValueVisible:
    If False, the control to see/change the color by its Hex value is not visible.
    The default is True.
    If ColorParametersVisible is False, the hex control is not visible either regardless of this setting.

    SelectionParameter:
    Determines what will be selected with the third parameter bar and slider. It may be any of the six parameters: value/luminance, hue, saturation, red, green or blue.
    The default is luminance.

    Screenshot selecting Hue:

    Name:  WheelColorPicker_scr2.png
Views: 3607
Size:  49.5 KB

    DrawFixed:
    If False, the colors of the wheel or of the third parameter selection bar will be updated with the selection of the other. If True they will be fixed.
    The default value is True.

    SelectionParametersAvailable:
    Determines whether will be displayed a combo control from which the user can select the SelectionParameter and what parameters will be available to select.
    The default setting is to show the combo and allow to select Luminance/value or saturation.

    DrawFixedControlVisible:
    Determines whether will be displayed a control from which the user can toggle DrawFixed on/off.

    ColorSystemControlVisible:
    Determines whether will be displayed a control from which the user can switch from HSV to HSL color system.

    Color:
    Used to set the initial color and to get the chosen color.

    Context:
    You can set a string that sets the "context". It is used to save the recent colors in different lists for different contexts.

    Canceled (read only):
    Returns True if the user didn't press the OK button.

    Changed (read only):
    Returns True if the user changed the color and pressed the OK button
    It can be used instead of the return value of the Show function.

    The function to show the dialog is:

    Show:
    Returns True if the user actually changed the color and pressed the OK button.

    Methods:

    SetCompact:
    It is a helper method that sets DialogSizeBig (the default is False), RecentColorsVisible, ColorParametersVisible and SelectionParametersAvailable in a handy way.

    The result:

    Name:  WheelColorPicker_scr3.png
Views: 3748
Size:  40.4 KB

    SetComplete:
    It is a helper method that sets SelectionParametersAvailable, DrawFixedControlVisible and ColorSystemControlVisible in a handy way.

    The result:

    Name:  WheelColorPicker_scr4.png
Views: 3932
Size:  45.6 KB

    SetCaption:
    Can be used to change the captions of the dialog for the translation to other languages.
    See an example in the next post.

    for example:
    Code:
    iDlg.SetCaption cdCaptionGreen, "Verde"
    A simple usage of the dialog would be:

    Code:
        Dim oDlg As New ColorDialog
        
        oDlg.Color = Picture1.BackColor
        If oDlg.Show Then
            Picture1.BackColor = oDlg.Color
        End If
    Note: In the project there is an UserControl, named ColorWheel, that can be used outside this color dialog in cases where there is the need to select colors.

    To use this color dialog, the files that you need to add to your project are three:
    1) ColorWheel.ctl (also copy its companion file ColorWheel.ctx)
    2) frmWheelColorDialog.frm
    3) ColorDialog.cls

    When you attempt to add the frmWheelColorDialog.frm file to your project, you'll experience an error message saying "error loading, read the log file for details" and in the log file it says that ColorDialogTest.ColorWheel was not a loaded control class.
    To avoid that message:

    Option 1:
    a) Open your project, go to menu Project, Properties. See what's the project's name (not title, but name, on the first tab), copy it.
    b) Manually edit the frmWheelColorDialog.frm with Notepad.
    Find the line: Begin ColorDialogTest.ColorWheel ColorWheel1 and replace it with Begin YourProjectName.ColorWheel ColorWheel1.
    c) Save
    d) Add to your project the files in this order: ColorWheel.ctl, frmWheelColorDialog.frm and ColorDialog.cls.

    Option 2:
    a) Open your project, go to menu Project, Properties. See what's the project's name (not title, but name, on the first tab), copy it.
    b) Open the project that you downloaded here, the file is ColorDialog_Test.vbp.
    c) Go to menu Project, Properties, and in the first tab go to the name of the project, it will say "ColorDialogTest", then change that with the name of your project that you have copied. Click OK.
    d) Save. The name of the vbp file does not matter. Close the project.
    e) Now go to your project and add the files in this order: ColorWheel.ctl, frmWheelColorDialog.frm and ColorDialog.cls.

    Download from GitHub.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width