Software Developer's Kit - ChemDraw

Send comments on this topic
Color Property
See Also 

Description

Member of ChemDraw Control.Geometry.

Sets and returns the color of this geometry.

Property type

Read-write property

Syntax

Visual Basic
Public Property Color() As ULong

Return Type

ULong

Remarks

This property sets and returns the object´s color as an unsigned long data type.

Color can be read as a hexadecimal number, which is easier to interpret as a RGB (Red-Green-Blue) type of definition for color.
Example: Red is 0000FF hex (255 will be returned as a decimal value)
              Green is 00FF00 hex (65280 will be returned as a decimal value)
              Blue is 1FF0000 hex (6711680 will be returned as a decimal value)

ChemDraw works with an 8 color palette, which may be expanded by the user.
One way to enable a color that is not in the palette, is to use Object.Settings.Color.

Example

'Declares variable vObject - Object can be any ChemDraw object
 Dim vObject AsChemDrawControl10Ctl.Object
'Checks that there is an object loaded in the variable
 If  Selection.Objects.Count < 1 Then
     Exit Sub
 End If

 Private Sub cmdColor1_click()
   'Example 1: Returns the color of the selected object
    Text1.text = vObject.Color
   'Example 2: Turns to red the last object selected
   For Each myObjectIn Selection.Objects
        If  myObject.Selected = True Then 
            Set vObject = myObject
             vObject.Color = val(Text1.text)
        End If
    Next
    'Example 3: colors selected object. Color is chosen from CommonDialog.Color (color palette)
     vObject.Color = "&H" & Hex(CommonDialog.Color)
    'Uses hexadecimal (base 16) color definition:  CommonDialog.Color = "&H" & Hex(vObject.Color)
End Sub 

Private Sub cmdColor2_Click() 
   'uses a common dialog 
    codColor.Flags = cdlCCRGBInit
    codColor.Color = MyObject.Color 
   'opens common dialog
    codColor.Action = 3 
   'reads the common dialog 
    myObject.Color = codColor.Color 
   'shows the selected color in hex and decimal
    lblhex.Caption = "H&" & Hex (MyObject.Color)
    lbldec.Caption = MyObject.Color
End Sub

See Also