Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Draw an arrow on a form at design time 2

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
0
0
GB
hi All

How do I put a simple arrow on a form? Do I need to use a TImage component? it's a static arrow, not editable by the use (yet).

lou
 
You could use the form.Canvas property which allows you to set a pen color and style, and use MoveTo and LineTo to do basic drawing.

Good luck!
TealWren
 
If you wanna follow TealWren's advice, you could use the following code:

Code:
procedure TForm1.FormPaint(Sender: TObject);
begin
  DrawArrow;
end;

procedure TForm1.DrawArrow;
begin
  Canvas.Pen.Color := clBlack;
  Canvas.MoveTo(0, 50);
  Canvas.LineTo(0, 70);
  Canvas.LineTo(50, 70);
  Canvas.LineTo(50, 75);
  Canvas.LineTo(60, 60);
  Canvas.LineTo(50, 45);
  Canvas.LineTo(50, 50);
  Canvas.LineTo(0, 50);
  Canvas.Brush.Color := clRed;
  Canvas.FloodFill(30, 60, clBlack, fsBorder);
end;

Note: to ensure the arrow stays on the form you must call the DrawArrow function from the form's OnPaint event, otherwise the drawing will not be redrawn when the form regains focus again. It will have been, in effect, wiped off the form. Let me know if you have any more questions about this technique.

Alternatively, if you have already drawn the arrow in 'Image Editor' or another program and have it saved as a bmp, for instance, you can then place that bmp directly onto the form using the following code:
Code:
procedure TForm1.FormPaint(Sender: TObject);
begin
  // Adds specified bitmap to top-left of form
  DrawBitmap('C:\MyArrow.bmp', 0, 0);
end;

procedure Form1.DrawBitmap(const Filename: String; const x,y: Integer);
var
  Bmp: TBitmap;
begin
  if FileExists(Filename) then
  begin
    Bmp := TBitmap.Create;
    try
      Bmp.LoadFromFile(Filename);
      Canvas.Draw(x, y, Bmp);
    finally
      Bmp.Free;
    end;
  end
  else 
    ShowMessage('Unable to locate ' + Filename);
end;

Hope this helps! [lightsaber]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top