RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomImageList.Draw Method (TCanvas, Integer, Integer, Integer, Boolean)

Draws the image specified by the Index parameter onto the provided Canvas.

Pascal
procedure Draw(Canvas: TCanvas; X: Integer; Y: Integer; Index: Integer; Enabled: Boolean = True); overload;
procedure Draw(Canvas: TCanvas; X: Integer; Y: Integer; Index: Integer; ADrawingStyle: TDrawingStyle; AImageType: TImageType; Enabled: Boolean = True); overload;
C++
__fastcall Draw(TCanvas Canvas, int X, int Y, int Index, Boolean Enabled = True);
__fastcall Draw(TCanvas Canvas, int X, int Y, int Index, TDrawingStyle ADrawingStyle, TImageType AImageType, Boolean Enabled = True);

Use the Draw method to draw one of the images in the image list onto a specified canvas. 

Canvas is the drawing surface on which to render the image. 

X and Y specify the location where the top-left corner should appear on Canvas. 

Index indicates which image to draw, where 0 specifies the first image, 1 specifies the second image, and so on. 

ADrawingStyle indicates how the color of the image may be altered. If this parameter is not specified, Draw uses the value of the DrawingStyle property. 

AImageType indicates whether to draw the image or its associated mask. If this parameter is not specified, Draw uses the value of the ImageType property. 

Enabled indicates whether the image appears as a gray-mapped image. If Enabled is false, Draw renders a gray-mapped version of the image. Because Enabled has a default value of true, this parameter can be omitted if the image should not be grayed.  

C++ Examples: 

 

/*
The following code is the OnDrawPanel event handler of a
status bar.  It draws each panel of the status bar, adding
text and icons stored in ImageList1. The image list contains
as many icons as there are header sections.  This example
requires a populated image list and a statusbar with several
panels added to the Panels property.  Select each panel and
set the Style property to psOwnerDraw.
*/
void __fastcall TForm1::StatusBar1DrawPanel(TStatusBar *StatusBar,
        TStatusPanel *Panel, const TRect &Rect)
{
  TCanvas *canvas = StatusBar->Canvas;
  canvas->Brush->Color = clRed;
  canvas->FillRect(Rect);
  canvas->Font->Color = clYellow;
  ImageList1->Draw(canvas,Rect.Left,Rect.Top, Panel->Index, true);
  canvas->TextOut(Rect.left + 30, Rect.top + 2, "Panel" + IntToStr(Panel->Index));
}

 

Delphi Examples: 

{
The following code is the OnDrawPanel event handler of a
status bar.  It draws each panel of the status bar, adding
text and icons stored in ImageList1. The image list contains
as many icons as there are header sections.  This example
requires a populated image list and a statusbar with several
panels added to the Panels property.  Select each panel and
set the Style property to psOwnerDraw.
}
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);
begin
with StatusBar1.Canvas do
  begin
    Brush.Color := clRed;
    FillRect(Rect);
    Font.Color := clYellow;
    ImageList1.Draw(StatusBar1.Canvas,Rect.Left,Rect.Top,Panel.Index);
    TextOut(Rect.left + 30, Rect.top + 2, 'Panel' + IntToStr(Panel.Index));
  end;
end;

 

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