RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomListView.Canvas Property

Gives access to the list view's canvas.

Pascal
property Canvas: TCanvas;
C++
__property TCanvas Canvas;

Use the Canvas property to paint to the list view's canvas during custom draw events such as OnDrawItem, OnCustomDraw, OnCustomDrawItem, OnCustomDrawSubItem, OnAdvancedCustomDraw, OnAdvancedCustomDrawItem, and OnAdvancedCustomDrawSubItem.  

C++ Examples: 

 

/*
The following code uses ClientRect to find and draw a line
from the top left to the bottom right of the current
control.  Select a TControl in the ListBox list.  This
example assumes that the current object is a descendent of
TControl and has a public Canvas property.
*/
{
  TPoint APoint = Point(X, Y);
  int Index = ListBox1->ItemAtPos(APoint, True);
  TListView *myListView;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TListView")
  {
    myListView = (TListView *)ListBox1->Items->Objects[Index];
    // make sure we are using the TControls canvas and not the from's!
    myListView->Canvas->MoveTo(myListView->ClientRect.Left, myListView->ClientRect.Top);
    myListView->Canvas->LineTo(myListView->ClientRect.Right, myListView->ClientRect.Bottom);
    myListView = NULL;
  }
}

 

Delphi Examples: 

{
The following code uses ClientRect to find and draw a line
from the top left to the bottom right of the current
control.  Select a TControl in the ListBox list.  This
example assumes that the current object is a descendent of
TControl and has a public Canvas property.
}
  if (ListBox1.Items.Objects[Index] is TListView) then
  begin
    myListView:= (ListBox1.Items.Objects[Index] as TListView);
    with myListView.ClientRect do
    begin // make sure we are using the TControl's canvas and not the form's!
      myListView.Canvas.MoveTo(Left, Top);
      myListView.Canvas.LineTo(Right, Bottom);
    end;
  myListView:= nil;
  end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!