SetBackgroundColor Method (ActiveX)

Sets a background color value for the specified row types.

Supported platforms: Windows only

Signature

VBA:

object.SetBackgroundColor rowTypes, pColor
object

Type: Table, TableStyle

The objects this method applies to.

rowTypes

Access: Input-only

Type: AcRowType enum

The row types to change.

  • acDataRow
  • acHeaderRow
  • acTitleRow
  • acUnknownRow
pColor

Access: Input-only

Type: AcCmColor

The AutoCAD true color object to apply to the specified row type.

Return Value (RetVal)

No return value.

Remarks

No additional remarks.

Examples

VBA:

Sub Example_SetBackgroundColor()
    ' This example creates a TableStyle object and sets values for
    ' the style name and other attributes.
    
    Dim dictionaries As AcadDictionaries
    Set dictionaries = ThisDrawing.Database.dictionaries
  
    Dim dictObj As AcadDictionary
    Set dictObj = dictionaries.Item("acad_tablestyle")
  
    ' Get the current TableStyle object
    Dim tableStyle As AcadTableStyle
    Set tableStyle = dictObj.Item(ThisDrawing.GetVariable("CTABLESTYLE"))
  
    Dim colCurrent As AcadAcCmColor, colRowCurrent As AcadAcCmColor, colNoneCurrent As Boolean
    Set colCurrent = tableStyle.GetBackgroundColor(AcRowType.acDataRow + AcRowType.acTitleRow)
    Set colRowCurrent = tableStyle.GetColor(acDataRow)
    colNoneCurrent = tableStyle.GetBackgroundColorNone(AcRowType.acHeaderRow)

    MsgBox "Table colors " & vbLf & _
           "Background ACI value = " & colCurrent.ColorIndex & vbLf & _
           "Row Text ACI value = " & colRowCurrent.ColorIndex & vbLf & _
           "Background None = " & colNoneCurrent
  
    Dim col As AcadAcCmColor
    Set col = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.20")
    col.SetRGB 0, 0, 255
    tableStyle.SetBackgroundColor AcRowType.acTitleRow, col
    col.SetRGB 255, 0, 0
    tableStyle.SetColor AcRowType.acDataRow, col
    If colNoneCurrent = False Then
        tableStyle.SetBackgroundColorNone AcRowType.acHeaderRow, True
    Else
        tableStyle.SetBackgroundColorNone AcRowType.acHeaderRow, False
    End If
      
    Dim colNew As AcadAcCmColor, colRowNew As AcadAcCmColor, colNoneNew As Boolean
    Set colNew = tableStyle.GetBackgroundColor(AcRowType.acTitleRow)
    Set colRowNew = tableStyle.GetColor(acDataRow)
    colNoneNew = tableStyle.GetBackgroundColorNone(acHeaderRow)

    MsgBox "Table colors " & vbLf & _
           "Background ACI value = " & colNew.ColorIndex & vbLf & _
           "Row Text ACI value = " & colRowNew.ColorIndex & vbLf & _
           "Background None = " & colNoneNew
  
    tableStyle.SetBackgroundColor AcRowType.acTitleRow, colCurrent
    tableStyle.SetColor AcRowType.acDataRow, colRowCurrent
    tableStyle.SetBackgroundColorNone AcRowType.acHeaderRow, colNoneCurrent
    
    MsgBox "Reset the table style back to its original values."
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_SetBackgroundColor()
    ;; This example creates a TableStyle object and sets values for 
    ;; the style name and other attributes.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    (setq dictionaries (vla-get-Dictionaries doc))
    (setq dictObj (vla-Item dictionaries "acad_tablestyle"))
    
    ;; Create the custom TableStyle object in the dictionary
    (setq keyName "NewStyle"
          className "AcDbTableStyle")
  
    (setq customObj (vla-AddObject dictObj keyName className))
      
    (vla-put-Name customObj "NewStyle")
    (vla-put-Description customObj "New Style for My Tables")
  
    (vla-put-FlowDirection customObj acTableBottomToTop)
    (vla-put-HorzCellMargin customObj 0.22)
    (vla-put-BitFlags customObj 1)
    (vla-SetTextHeight customObj (+ acDataRow acTitleRow) 1.3)
    (vla-SetTextStyle customObj (+ acDataRow acTitleRow) "Standard")

    (setq col (vlax-create-object "AutoCAD.AcCmColor.20"))
    (vla-SetRGB col 12 23 45)
  
    (vla-SetBackgroundColor customObj (+ acDataRow acTitleRow) col)
    (vla-SetBackgroundColorNone customObj acHeaderRow :vlax-false)
    (vla-SetGridVisibility customObj (+ acHorzInside acHorzTop) (+ acDataRow acTitleRow) :vlax-true)
    (vla-SetAlignment customObj (+ acDataRow acTitleRow) acBottomRight)
    (vla-SetRGB col 244 0 0)
    (vla-SetGridColor customObj (+ acHorzTop acHorzInside) acDataRow col)
      
    (alert (strcat "Table Style Name = " (vla-get-Name customObj)
                   "\nStyle Description = " (vla-get-Description customObj)
                   "\nFlow Direction = " (itoa (vla-get-FlowDirection customObj))
                   "\nHorzontal Cell Margin = " (rtos (vla-get-HorzCellMargin customObj) 2)
                   "\nBit Flags = " (itoa (vla-get-BitFlags customObj))
                   "\nTitle Row Text Height = " (rtos (vla-GetTextHeight customObj acTitleRow) 2)
                   "\nTitle Row Text Style = " (vla-GetTextStyle customObj acTitleRow)
                   "\nGrid Visibility for HorizontalBottom TitleRow  = " (if (= (vla-GetGridVisibility customObj acHorzBottom acTitleRow) :vlax-true) "True" "False")
                   "\nTitle Row Alignment = " (itoa (vla-GetAlignment customObj acTitleRow))
	                  "\nHeader Suppression = " (if (= (vla-get-HeaderSuppressed customObj) :vlax-true) "True" "False")
	         )
    )
    (vlax-release-object col)
)