VCL: Example: Text at mouse position

<< Click to Display Table of Contents >>

Navigation:  Tasks > Draw Shapes / Text objects on PDF >

VCL: Example: Text at mouse position

At the end of the example code a font dialog is opened to let the user change a font.

 

var

  t: TPDFDrawObjectRec;

  s : AnsiString;

begin

  FillChar(t, SizeOf(t), 0);

  t.grtyp := 100;

  t.typparam := 2000; // Textfield, Height = 20

  t.ColorText := ColorToRGB( clBlue ); // Text Color

  t.ColorPen := ColorToRGB( clYellow ); // Background Color

  t.ObjectOptions := 4+8; // Center Text + Opaque

  // use 2048 instead of 4 for right aligned text 

 

  t.ColorBrush := clYellow;

  // Get the page number

  t.PageNo :=  WPViewPDF1.command(COMPDF_GetPageUnderMouse);

 

  // Position of MOUSE on the page:

  t.x := WPViewPDF1.command(COMPDF_GetPageLogX);

  t.y := WPViewPDF1.command(COMPDF_GetPageLogY);

  t.h := 72;

  t.w := 72*3;

 

  t.Angle := 45;

 

  t.FontSize := 55*100;

 

  if FontDialog1.Execute then

  begin

     s := '"Font=' + FontDialog1.Font.Name + '"';

     WPViewPDF1.AddDrawObject(wpAddNow, '', t, 

      'This text in mouse position', PAnsiChar(s));

  end;

end;

 

 

If you want the user to "draw" the object with the mouse use

 

AddDrawObject(wpDrawAndAdd ...