TImageCanvas (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code uses ClientRect to find and draw a line from the upper left to the lower right of the current control. Select a TControl in the ListBox list. This example assumes that the current object is a descendant of TControl and has a public Canvas property.

Code

  if (ListBox1.Items.Objects[Index] is TImage) then
  begin
    myImage:= (ListBox1.Items.Objects[Index] as TImage);
    with myImage.ClientRect do
    begin // Make sure you are using the canvas of the TControl, and not the form's canvas.
      myImage.Canvas.MoveTo(Left, Top);
      myImage.Canvas.LineTo(Right, Bottom);
    end;
  myImage:= nil;
  end;

Uses

Description

The following example paints a cross-hatched ellipse onto Image1, which is a TImage on the form when you click Button1.

Code

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Image1 do begin
    Canvas.Brush.Color := clRed;
    Canvas.Brush.Style := bsDiagCross;
    Canvas.Ellipse(0, 0, Image1.Width, Image1.Height);
  end;
end;

Uses