Ciaran
2019-01-13T13:13:50Z
Hi Igor
Was going to ask a "how do I ..." question when I realised that I could make it happen ... myself.
The question was: "How can I set the foreground and background colours of a combobox item list?"

Well, I added these properties to the oODCombo object(with the US spelling "color"): hope that you don't mind. I did it thus;
In the Class Module "cODCombo"
1. I added 2 private variables and 2 properties

Private m_lForeColor As Long
Private m_lBackColor As Long
Public Property Let ForeColor(ByVal lColor As Long)
    m_lForeColor = lColor
End Property

Public Property Get ForeColor() As Long
    ForeColor = m_lForeColor
End Property

Public Property Let BackColor(ByVal lColor As Long)
    m_lBackColor = lColor
End Property

Public Property Get BackColor() As Long
    BackColor = m_lBackColor
End Property
2. I changed the Class_Initialize so that we have the usual defaults (that you had in your code)
Private Sub Class_Initialize()
   ' Default values
   m_lHeight = 120
   m_lWidth = 0 ' Width equals column width
   m_lMaxItemHeight = MIN_ITEM_HEIGHT
   m_lMaxHeightInItems = DEFAULT_MAX_HEIGHT_IN_ITEMS
   m_bAutoExpand = True
   m_lForeColor = GetSysColor(COLOR_WINDOWTEXT)
   m_lBackColor = GetSysColor(COLOR_WINDOW)
End Sub

3. Finally I changed the Function plDrawItem thus - kept the old values for good measure :)
   If bSelected Then
      hBrush = GetSysColorBrush(COLOR_HIGHLIGHT)
      lBkColor = GetSysColor(COLOR_HIGHLIGHT)
      lTxtColor = GetSysColor(COLOR_HIGHLIGHTTEXT)
   Else
      hBrush = m_lBackColor  'GetSysColorBrush(COLOR_WINDOW)
      lBkColor = m_lBackColor '= GetSysColor(COLOR_WINDOW)
      lTxtColor = m_lForeColor '= GetSysColor(COLOR_WINDOWTEXT) '
   End If

Next in Class ComboObject I added the following 2 properties

Public Property Let ForeColor(lForeColor As Long)
    m_objCbo.ForeColor = lForeColor
End Property
Public Property Get ForeColor() As Long
    ForeColor = m_objCbo.ForeColor
End Property
Public Property Let BackColor(lBackColor As Long)
    m_objCbo.BackColor = lBackColor
End Property
Public Property Get BackColor() As Long
    BackColor = m_objCbo.BackColor
End Property

And there it is! Combos now have fore colour and if you really want to ... back colour.
and as a code sample, it looks like this

        With .Combos("DoseInterval")
            Set .Font = ComboFnt
            .ForeColor = vbRed
            .BackColor = vbYellow
            .AutoAdjustWidth
        End With
igrid with fore and back colour.jpg

Click to View Image140 View(s)



But I'm left feeling a bit empty. You see I would rather see the back colour of the combobox container set to the back colour of the cell containing the combobox and not just the text of each item: it would look neater. Problem is, I'm stumped as to how to do this.
In ShowDropDown of oODCombo I tried setting the back colour after you call showdropdown but it doesn't do what I want.
SendMessageByLongW m_hWnd, CB_SHOWDROPDOWN, 1, 0
SetBkColor m_hWnd, m_lBackColor '<--- or any colour, really


Oh well, this has achieved what I wanted so I'm not whinging.

Cheers
Ciaran
Igor/10Tec
2019-01-15T16:21:59Z
Read the comment before the following statement in the cODCombo source code:

SendMessageByLongW m_hWnd, CB_SHOWDROPDOWN, 1, 0

You will see the mention of the WM_CTLCOLORLISTBOX  message. This is the right place to set set the required foreground/background colors for the whole drop-down list. According to the MSDN,

引用:

If an application processes this message, it must return a handle to a brush. The system uses the brush to paint the background of the list box.



Hope that helps. In any case, your suggestion is a good candidate to add it to iGrid in future updates - like personal foreground/background colors for every item.
Ciaran
2019-01-16T02:47:59Z
Untitled.png

Click to View Image131 View(s)



hmmmm

And on your idea of fore and backcolor of each item in the list ... add font to that and we have a full set: this is certainly on my radar.

Something like this structure, perhaps
Private Type TComboItemInfo
   sText As String
   lWidth As Long
   lTextHeight As Long
   lTextWidth As Long
   lItemHeight As Long
   vValue As Variant
   iIconIndex As Integer
   lForeColor As Long
   lBackColor As Long
   mFont As StdFont
   bUsed As Boolean ' used to mark currently used items
End Type