Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 2-10-2020. The page as it is now.

Canvas draw vertical line on form/de

Zurück zur Seite Code Beispiele.

Das Unterprogramm zeigt, wie mit Canvas auf einem Formular eine vertikale Linie gezeichnet wird.

pascal
uses
  Forms, Graphics, ...;

  ...

procedure subVertikaleLinie(Form: TForm; w32X, w32Y : LongWord; bytStrich: Byte; w16Farbe: Word);
// Alle Zahlen und Berechnungen sind in Pixel
begin
  
  with Form do
  begin
    // Legt den Punkt fest, ab dem das Zeichnen beginnt
    Canvas.MoveTo(w32X, w32Y);
    // Legt die Farbe des Strichs fest
    Canvas.Pen.Color := w16Farbe;
    // Legt die Breite des Strichs fest
    Canvas.Pen.Width := bytStrich;
    // Zeichnet einen Strich
    // Parameter:
    // LineTo(Länge ab dem Startpunkt, Abstand zur Oberen Formularkante)
    Canvas.LineTo(Width - w32X, w32Y);
  end;
  
end;

...

Wenn dieses Unterprogramm im Ereignis OnPaint des Formulars eingetragen wird, wird die Linie bei jeder Formularänderung neu gezeichnet.

Beispiel:

pascal
uses
  Forms, Graphics, ...;

  ...

procedure TForm1.FormPaint(Sender: TObject);
begin
  // Parameter für das Unterprogramm:
  // Formularname, X-Startkoordinate, Y-Startkoordinate, Strichbreite, Farbe
  subVertikaleLinie(Form1, 10, 50, 2, clred);
end;

...

From the Free Pascal wiki, page "Canvas draw vertical line on form/de", as it stood on 2020-02-10 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.