[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Drawing an image on a treeview object

Posted on 2005-04-17
2
Medium Priority
?
1,980 Views
Last Modified: 2008-01-09
I need to paint an image on a treeview object, the delphi example doesn't  work

Thanks
0
Comment
Question by:amielDorel
2 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 13802518
What do you mean the delphi example does not work? Please explain what you are experiencing....

It works for me!

sholmes
0
 
LVL 11

Accepted Solution

by:
pcsentinel earned 750 total points
ID: 13805565
I presume you want to draw a bitmap or something in  column, if so you can use something like this

procedure TfrmMain.lvListAdvancedCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
  var DefaultDraw: Boolean);
//custom draw routine for the listview
      procedure GetRect(Col: integer; var Rect: TRect);
  var
        li: integer;
  begin
    for li:=0 to Col do
              Rect.Left:=Rect.Left+ Sender.Column[li].Width;
    Rect.Right:=Rect.Left+ Sender.Column[succ(Col)].Width;
  end;
var
      lRect: TRect;
  li: integer;
begin
  if (Stage=cdPrePaint) then
  begin
    if Item.Selected then
    begin
      lvList.Canvas.Brush.Color:=clHighlight;
      lvList.Canvas.Font.Color:=clHighlightText;
    end
    else
    begin
      lvList.Canvas.Brush.Color:=clWindow;
      lvList.Canvas.Font.Color:=clWindowText
    end;
            DefaultDraw:=false;
    lRect := Item.DisplayRect(drBounds);
    inc(lRect.Left,4);
    if Item.Caption='1' then
      imlIcons.Draw(lvList.Canvas,lRect.Left,lRect.Top,0);
    for li:=0 to pred(Item.SubItems.Count) do
    begin
      if li=0 then
      begin
                lRect := Item.DisplayRect(drBounds);
                GetRect(li,lRect);
        inc(lRect.Left,6);
        if Item.SubItems[0]='1' then
          imlIcons.Draw(lvList.Canvas,lRect.Left,lRect.Top,1);
      end
      else
      begin
                lRect := Item.DisplayRect(drBounds);
                GetRect(li,lRect);
                lvList.Canvas.FillRect(lRect);
        inc(lRect.Top,2);
        inc(lRect.Left,3);
            DrawText(lvList.Canvas.Handle,pChar(Item.SubItems[li]),Length(Item.SubItems[li]),lRect, DT_END_ELLIPSIS or DT_LEFT or DT_VCENTER or DT_NOPREFIX);
      end;
    end;
  end;
end;


regards
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question