TWPORTFTextBox.Create

Top  Previous  Next

The following low level code inserts a text box by creating an instance of TWPORTFTextBox.

You can of adapt this code to use the TParagraph.InsertObject procedure if you do not want to insert at cursor position. Otherwise simply use TextObjects.InsertTextBox, as mentioned above.

 

var obj: TWPORTFTextBox;

 txtobj: TWPTextObj;

begin

if WPRichText1.CursorOnText.Kind <> wpIsBody then

   ShowMessage('Cannot insert object in Object') else

begin

   obj := TWPORTFTextBox.Create(WPRichText1);

   obj.WidthTW  := 3000;

   obj.HeightTW := 1000;

   obj.MakeUniqueName;

   obj.AsString := '<b>Textbox</b> text in HTML, ANSI or RTF format!';

   txtobj := WPRichText1.TextObjects.InsertMovableImage(obj);

  if txtobj <> nil then

  begin

     txtobj.Mode := txtobj.Mode + [ wpobjObjectUnderText, wpobjCreateAutoName ];

     txtobj.RelX := 1440;

     txtobj.RelY := 0;

    // optional

     txtobj.Frame := [wpframe1pt,wpframeShadow];

     WPRichText1.ReformatAll;

     obj.Edit;

     WPRichText1.SetFocus;

  end;

end;

end;