Customize item colors

The place for threads about TimoSoft ExplorerListView.
Post Reply
tpssoft
Cadet
Posts: 2
Joined: 05 Apr 2006, 15:09

Customize item colors

Post by tpssoft »

I love the controls. I've been looking for a VB6 listview control that can handle the XP styles. I have found the themes & callbacks a bit confusing. My question is; how can I customize each individual subitems forecolor and backcolor?
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Post by TiKu »

You can do this using Custom Draw. The following should work:

Code: Select all

Private Sub ExLvw_CustomDraw(ByVal listItem As ExLVwLibUCtl.IListViewItem, ByVal listSubItem As ExLVwLibUCtl.IListViewSubItem, TextColor As stdole.OLE_COLOR, TextBackColor As stdole.OLE_COLOR, ByVal drawStage As ExLVwLibUCtl.CustomDrawStageConstants, ByVal itemState As ExLVwLibUCtl.CustomDrawItemStateConstants, ByVal hDC As Long, drawingRectangle As ExLVwLibUCtl.RECTANGLE, furtherProcessing As ExLVwLibUCtl.CustomDrawReturnValuesConstants)
  Select Case drawStage
    Case CustomDrawStageConstants.cdsPrePaint
      ' tell the control that we want to customize item drawing
      furtherProcessing = CustomDrawReturnValuesConstants.cdrvNotifyItemDraw

    Case CustomDrawStageConstants.cdsItemPrePaint
      ' TODO: Change TextBackColor and TextColor to make the whole item (listItem) appear in these colors.

      ' tell the control that we've changed the colors and want to customize sub-item drawing
      furtherProcessing = CustomDrawReturnValuesConstants.cdrvNewFont Or CustomDrawReturnValuesConstants.cdrvNotifySubItemDraw

    Case CustomDrawStageConstants.cdsSubItemPrePaint
      If listSubItem.Index > 0 Then
        ' TODO: Change TextBackColor and TextColor to make the sub-item (listSubItem) appear in these colors.
        ' NOTE: Sub-item 0 is the item itself.

        ' tell the control that we've changed the colors
        furtherProcessing = CustomDrawReturnValuesConstants.cdrvNewFont
      End If
  End Select
End Sub
Also take a look at the "Fonts and Colors" sample.

HTH
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
tpssoft
Cadet
Posts: 2
Joined: 05 Apr 2006, 15:09

Post by tpssoft »

Thanks that worked great. I saw the Font sample but couldn't understand the how the case statement worked. If you have a sample of how one could change the group format (backcolor, gradient, font etc...) i'd really appreciate it. Again thanks and keep up the great work!
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Post by TiKu »

You need the GroupCustomDraw event to do this.

Code: Select all

Private Sub ExLvw_GroupCustomDraw(ByVal Group As ExLVwLibUCtl.IListViewGroup, textColor As stdole.OLE_COLOR, Alignment As ExLVwLibUCtl.AlignmentConstants, ByVal drawStage As ExLVwLibUCtl.CustomDrawStageConstants, ByVal groupState As ExLVwLibUCtl.CustomDrawItemStateConstants, ByVal hDC As Long, drawingRectangle As ExLVwLibUCtl.RECTANGLE, textRectangle As ExLVwLibUCtl.RECTANGLE, furtherProcessing As ExLVwLibUCtl.CustomDrawReturnValuesConstants)
  Const OPAQUE = 2
  Const TRANSPARENT = 1

  Select Case drawStage
    ' NOTE: you must do this in the cdsPrePaint stage, not in cdsItemPrePaint
    Case CustomDrawStageConstants.cdsPrePaint
      ' change the group's text color
      textColor = IIf(Group.ID = 1, vbRed, vbBlue)
      ' force the listview to draw the group text with an opaque background
      SetBkMode hDC, OPAQUE
      ' now set the text back color
      SetBkColor hDC, vbYellow
      ' set the font to use
      SelectObject hDC, hFont

      ' tell the listview that we've changed the font
      ' we also tell it to NOT draw the gradient
      furtherProcessing = CustomDrawReturnValuesConstants.cdrvNewFont Or CustomDrawReturnValuesConstants.cdrvNoGroupFrame

    Case CustomDrawStageConstants.cdsPostPaint
      ' reset to transparent text background
      SetBkMode hDC, TRANSPARENT
      ' TODO: draw your own gradient (should be possible using drawingRectangle and/or textRectangle)
  End Select
End Sub
I'm not sure whether it's really possible to draw your own gradient, but chances are good. Probably the largest problem is to calculate the gradient's position. Unfortunately I've found no way to tell the underlying SysListView32 window to simply use a custom color to draw the gradient.

TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Post Reply