OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 28-07-2004, 14:43
Jon Lorber
Guest
 
Posts: n/a
Default Retrieve Color Values from Selected Object

I've searched and found a few topics on retriving color values but none that show specifically how retrieve a color value into a variable that could be displayed in a dialog.

For example I want to create a dialog with a text box that displays the color value of each component in RGB or CMYK.

Thanks in advance!
Reply With Quote
  #2  
Old 18-08-2004, 21:46
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Retrieve Color Values from Selected Object

Jon,

Actually it's not all that difficult. First, you need to be more specific what color you want to get. Is that the color of a uniform object fill, or the color of outline, or any of the colors of the fountain fill, etc? CorelDRAW can use colors in many ways. But let's assume you need the color of a uniformly filled object.

Here is how you do it:

Code:
Sub ShowFillColor()
    Dim clr As Color
    Dim r As Long, g As Long, b As Long
    Dim c As Long, m As Long, y As Long, k As Long
    
    If ActiveShape.Fill.Type <> cdrUniformFill Then
        MsgBox "Please select an object with uniform fill", vbCritical
        Exit Sub
    End If
    
    Set clr = ActiveShape.Fill.UniformColor
    Select Case clr.Type
        Case cdrColorRGB
            r = clr.RGBRed
            g = clr.RGBGreen
            b = clr.RGBBlue
            MsgBox "RGB Color is " & r & "," & g & "," & b
            
        Case cdrColorCMYK
            c = clr.CMYKCyan
            m = clr.CMYKMagenta
            y = clr.CMYKYellow
            k = clr.CMYKBlack
            MsgBox "CMYK Color is " & c & "," & m & "," & y & "," & k
            
        Case cdrColorGray
            g = clr.Gray
            MsgBox "Grayscale Color is " & g
            
        Case Else
            MsgBox "Some other color: " & clr.Name
    End Select
End Sub
In the above example, the uniform fill of the selected object is analyzed and individual component values are displayed for RGB, CMYK and Grayscale colors. You can add more cases to the Select statement to add code for other color models such as HSB, HLS, etc.

The Color object has a lot of other useful methods and properties. You can perform color conversions, comparisons, and so on. You can use the Name property to get either the color name (such as "Red", "40% Black", etc) or get a string which contains individual color components. For example, if you have an object with red fill applied and run the following macro, here is what you'll get:

Code:
Sub ShowColorName()
    MsgBox "Color name is " & ActiveShape.Fill.UniformColor.Name
    MsgBox "Color components are " & ActiveShape.Fill.UniformColor.Name(True)
End Sub
you will see two message boxes reading:

1. Color name is Red
2. Color components are C:0 M:100 Y:100 K:0

This can be quite useful when presenting color information to the user.

I hope this helps.
Reply With Quote
  #3  
Old 19-08-2004, 07:24
Jon Lorber
Guest
 
Posts: n/a
Default

Oh it definitley does! Thank you so much!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bounding lines around an object toy4mud CorelDRAW CS 2 04-11-2004 11:56
Sorting entries in the object manager dan CorelDRAW/Corel DESIGNER VBA 1 18-08-2004 22:16
Finding Color Currently Selected in RGB or CMYK Palette AARRGGHHH CorelDRAW/Corel DESIGNER VBA 1 30-03-2004 09:03
Would you miss CorelScript object? Alex CorelDRAW/Corel DESIGNER VBA 32 04-02-2004 14:59
finding node angles? IanVincent CorelDRAW/Corel DESIGNER VBA 4 12-12-2003 23:32


All times are GMT -5. The time now is 20:43.


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