Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Draw checkboxes in a virtual mode TListView Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
121
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How do I get CheckBoxes when using a TListView with OwnerData set to true and using 
an OnData event method?

Answer:

1   { ... }
2   const
3     W_64: Word = 64; {Width of thumbnail in ICON view mode}
4     H_64: Word = 64; {Height of thumbnail size}
5     CheckWidth: Word = 14; {Width of check mark box}
6     CheckHeight: Word = 14; {Height of checkmark}
7     CheckBiasTop: Word = 2; {This aligns the checkbox to be in centered}
8     CheckBiasLeft: Word = 3; {In the row of the list item display}
9   
10  procedure DrawCheckMark(const ListViewX: TListView; Item: TListItem; Checked:
11    Boolean);
12  var
13    TP1, TP2: TPoint;
14    XBias, YBias: Integer;
15    OldColor: TColor;
16    BiasTop, BiasLeft: Integer;
17    Rect1: TRect;
18  begin
19    GetCheckBias(XBias, YBias, BiasTop, BiasLeft, ListViewX);
20    OldColor := ListViewX.Canvas.Pen.Color;
21    TP1 := Item.GetPosition;
22    if Checked then
23      ListViewX.Canvas.Brush.Color := clBlack;
24    Rect1.Left := Item.Left - CheckWidth - BiasLeft + 1 + XBias;
25    Rect1.Top := Tp1.Y + BiasTop + 1 + YBias;
26    Rect1.Right := Item.Left - BiasLeft - 1 + XBias;
27    Rect1.Bottom := Tp1.Y + BiasTop + CheckHeight - 1 + YBias;
28    ListViewX.Canvas.FillRect(Rect1);
29    if Checked then
30      ListViewX.Canvas.Brush.Color := clBlue
31    else
32      ListViewX.Canvas.Brush.Color := clBlack;
33    ListViewX.Canvas.FrameRect(Rect1);
34    ListViewX.Canvas.FrameRect(Rect(Rect1.Left - 1, Rect1.Top - 1,
35      Rect1.Right + 1, Rect1.Bottom + 1));
36    if Checked then
37    begin
38      ListViewX.Canvas.Pen.Color := clLime;
39      TP2.X := Item.Left - BiasLeft - 2 + XBias;
40      TP2.Y := Tp1.Y + BiasTop + 2 + YBias;
41      ListViewX.Canvas.PenPos := TP2;
42      ListViewX.Canvas.LineTo(Item.Left - BiasLeft - (CheckWidth div 2) +
43        XBias, Tp1.Y + BiasTop + (CheckHeight - 2) + YBias);
44      ListViewX.Canvas.LineTo(Item.Left - BiasLeft - (CheckWidth - 2) + XBias,
45        Tp1.Y + BiasTop + (CheckHeight div 2) + YBias);
46      TP2.X := Item.Left - BiasLeft - 2 - 1 + XBias;
47      TP2.Y := Tp1.Y + BiasTop + 2 + YBias;
48      ListViewX.Canvas.PenPos := TP2;
49      ListViewX.Canvas.LineTo(Item.Left - BiasLeft - (CheckWidth div 2) - 1 + XBias,
50        Tp1.Y + BiasTop + (CheckHeight - 2) + YBias);
51      ListViewX.Canvas.LineTo(Item.Left - BiasLeft - (CheckWidth - 2) - 1 + XBias,
52        Tp1.Y + BiasTop + (CheckHeight div 2) + YBias);
53    end;
54    ListViewX.Canvas.Brush.Color := ListViewX.Color;
55    ListViewX.Canvas.Pen.Color := OldColor;
56  end;
57  
58  procedure GetCheckBias(var XBias, YBias, BiasTop, BiasLeft: Integer;
59    const ListView: TListView);
60  begin
61    XBias := 0;
62    YBias := 0;
63    if ListView.ViewStyle = vsICON then
64    begin
65      YBias := H_64 - CheckHeight;
66      XBias := 0;
67    end;
68    BiasTop := CheckBiasTop;
69    BiasLeft := CheckBiasLeft;
70    if ListView.ViewStyle <> vsReport then
71    begin
72      BiasTop := 0;
73      BiasLeft := 0;
74    end;
75  end;


In the OnCustomDrawItem event you would do something like this:

DrawCheckMark(FileListMenu.ListView1, Item, Item.Checked);

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC