RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomCombo.Canvas Property

Provides access to the drawing surface of the combo box.

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

Use Canvas as the drawing surface when customizing the way the combo box paints itself. For example, when using a TCustomCombo descendant that allows applications to draw combo box items in an OnDrawItem even, the OnDrawItem event handler uses Canvas for painting the customized items.  

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);
  TComboBox *myComboBox;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TComboBox")
  {
    myComboBox = (TComboBox *)ListBox1->Items->Objects[Index];
    // make sure we are using the TControls canvas and not the from's!
    myComboBox->Canvas->MoveTo(myComboBox->ClientRect.Left, myComboBox->ClientRect.Top);
    myComboBox->Canvas->LineTo(myComboBox->ClientRect.Right, myComboBox->ClientRect.Bottom);
    myComboBox = 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 TComboBox) then
  begin
    myComboBox:= (ListBox1.Items.Objects[Index] as TComboBox);
    with myComboBox.ClientRect do
    begin // make sure we are using the TControl's canvas and not the form's!
      myComboBox.Canvas.MoveTo(Left, Top);
      myComboBox.Canvas.LineTo(Right, Bottom);
    end;
  myComboBox:= nil;
  end;

 

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