78
« Last post by Chris Boss on February 25, 2022, 12:05:46 am »
A more complex approach is to use OnwerDraw.
From an example in the codeclips folder (cdrawlv.bas):
' *************************************************************************************
' Portions: Copyright Christoper R. Boss, 2003 to 2011
' All Rights Reserved !
' Registered EZGUI 5.0 users may use this code Royalty Free !
' *************************************************************************************
#COMPILE EXE
#DIM ALL
' --------------------
#INCLUDE "..\includes\ezgui50.inc"
' --------------------
DECLARE SUB Form1_Display(BYVAL Parent$)
DECLARE SUB Form1_Design()
DECLARE SUB Form1_Events(CID&, CMsg&, CVal&, Cancel&)
' ------------------------------------------------
%FORM1_LISTVIEW1 = 105
' ------------------------------------------------
DECLARE SUB FORM1_LISTVIEW1_Fill(BYVAL Mode&)
DECLARE SUB FORM1_LISTVIEW1_Change(BYVAL CVal&)
DECLARE SUB FORM1_LISTVIEW1_Select(BYVAL CVal&)
' --------------------
#INCLUDE "..\includes\ezwmain50.inc"
' --------------------
SUB EZ_Main(VerNum&)
EZ_DefFont 6, "Arial", 14, "BVA"
EZ_DefFont 7, "Arial", 10, "VA"
EZ_DefFont 8, "Arial", 10, "BVA"
EZ_DefFont 9, "Arial", 10, "IVA"
EZ_LoadPatternLib "", ""
Form1_Display ""
END SUB
SUB EZ_DesignWindow(FormName$)
SELECT CASE FormName$
CASE "FORM1"
Form1_Design
CASE ELSE
END SELECT
END SUB
SUB EZ_Events(FormName$, CID&, CMsg&, CVal&, Cancel&)
SELECT CASE FormName$
CASE "FORM1"
Form1_Events CID&, CMsg&, CVal&, Cancel&
CASE ELSE
END SELECT
END SUB
SUB Form1_Display(BYVAL Parent$)
EZ_Color -1, -1
EZ_Form "FORM1", Parent$, "OwnerDraw Listview", 0, 0, 67, 25, "C"
END SUB
GLOBAL Form1_FF&
SUB Form1_Design()
LOCAL FF&
'---------------------------------------------------------------
FF& = 9 ' - Offset for Font Numbers
Form1_FF& = FF& ' Global for ODButtons Draw code
'---------------------------------------------------------------
EZ_UseFont 7
EZ_Color 0,15
EZ_ListView %FORM1_LISTVIEW1, 3, 2, 60, 20, "Column 1{12}|Column 2{12}{C}|Column 3{12}{C}|", "SV-O?"
FORM1_LISTVIEW1_Fill -1
' --------------------------------------------------------------
END SUB
'
SUB SizeListViewItem(BYVAL CID&, BYVAL CVal&)
LOCAL W&, H&, Item1&, Item2&, NW!, NH!
IF EZ_StartOwnerSize(CVal&, W&, H&, Item1&, Item2&) THEN
EZ_GetTextSize 7, "XXX", NW!, NH!,0
H&=INT(NH!*1.5*2)
EZ_EndOwnerSize CVal&, W&, H&
END IF
END SUB
'
SUB DrawListviewItem(BYVAL CID&, BYVAL CVal&)
LOCAL hMyDC&, X2&, Y2&, IsSel&, IsGry&, IsDis&, IsChk&, IsFoc&, IsDef&
LOCAL X1&, Y1&, Item1&, IsEdit&, SubItem&, SubItem2&, CP$
LOCAL SX1&, SY1&, SX2&, SY2&, CW&, AW!, AH!
LOCAL IText$, IPictNum&, LVProp$
IF EZ_StartOwnerDraw(CVal&, hMyDC&, X2&, Y2&, IsSel&, IsGry&, IsDis&, IsChk&, IsFoc&, IsDef&) THEN
EZ_GetODItem CVal&, X1&, Y1&, Item1&, IsEdit&
CP$=EZ_GetLVColOrder("Form1", CID&,3)
IF Item1&>=0 THEN
SX1&=0
EZ_SaveState
FOR SubItem&=0 TO 2
CW&=EZ_GetLVColWidth("Form1", CID&, SubItem&)
SX2&=SX1&+CW&-1
IF IsSel& THEN
EZ_Color 15, 9
ELSE
IF (SubItem& MOD 2)=1 THEN
EZ_Color 0, 31
ELSE
EZ_Color 0, 23
END IF
END IF
IF SubItem&=1 THEN
' draw as a button
EZ_DCDraw hMyDC&, %EZ_FILL, SX1&, Y1&, SX2&, Y2&, 1, 1
' EZ_DCDraw hMyDC&, %EZ_EDGE_R, SX1&, Y1&, SX2&, Y2&, 1, 1
ELSE
EZ_DCDraw hMyDC&, %EZ_FILL, SX1&, Y1&, SX2&, Y2&, 1, 1
END IF
EZ_SaveState
IF IsSel& THEN EZ_Color 0,0
EZ_DCDraw hMyDC&, %EZ_LINE, SX2&, Y1&, SX2&, Y2&, 1, 0
EZ_DCDraw hMyDC&, %EZ_LINE, SX1&, Y2&, SX2&, Y2&, 1, 0
EZ_RestoreState
EZ_UseFont 7+SubItem& ' use different fonts
SubItem2&=VAL(PARSE$(CP$,"|",SubItem&+1)) ' get actual column
IF EZ_GetLVItem("Form1", CID&, IText$, IPictNum&, Item1&, SubItem2&, LVProp$ ) THEN
EZ_GetTextSize 7+SubItem2&, IText$, AW!,AH!,0
IF AW!>CW& THEN
EZ_SetPrintFormat 2, SX2&, Y2&, %EZ_LEFT OR %EZ_VCenter, 0
ELSE
EZ_SetPrintFormat 2, SX2&, Y2&, %EZ_CENTER OR %EZ_VCenter, 0
END IF
EZ_DCPrint hMyDC&, SX1&,Y1&, IText$
END IF
SX1&=SX2&+1
NEXT SubItem&
EZ_RestoreState
EZ_SetPrintFormat 0,0,0,0,0
END IF
EZ_EndOwnerDraw
END IF
END SUB
'
SUB Form1_Events(CID&, CMsg&, CVal&, Cancel&)
SELECT CASE CID&
CASE %EZ_Window
IF CMsg&=%EZ_Close THEN
END IF
CASE %FORM1_LISTVIEW1
IF CMsg&=%EZ_Change THEN
FORM1_LISTVIEW1_Change CVal&
END IF
IF CMsg&=%EZ_Selected THEN
FORM1_LISTVIEW1_Select CVal&
END IF
IF CMsg&=%EZ_OwnerSize THEN
SizeListViewItem CID&, CVal&
END IF
IF CMsg&=%EZ_OwnerDraw THEN
DrawListviewItem CID&, CVal&
END IF
CASE ELSE
END SELECT
END SUB
SUB FORM1_LISTVIEW1_Fill(BYVAL Mode&)
LOCAL R&, C&, Tmp$
IF Mode&=-1 THEN ' Initial Data
FOR R&=0 TO 50 ' Rows
FOR C&=0 TO 5 ' Columns
Tmp$="Item "+RIGHT$("00"+LTRIM$(STR$(R&)),2)+","+STR$(C&)+CHR$(13)+CHR$(10)+"OK -"+STR$(R&)
EZ_AddLVItem "Form1", %FORM1_LISTVIEW1, Tmp$, 0, R&, C&, ""
NEXT C&
NEXT R&
END IF
END SUB
SUB FORM1_LISTVIEW1_Change(BYVAL CVal&)
END SUB
SUB FORM1_LISTVIEW1_Select(BYVAL CVal&)
END SUB