ImageEn, unit iexRichEdit

TIERichEdit

Properties · Methods · Events · Demos · Examples

Declaration

TIERichEdit = class(TCustomRichEdit);


Description

TIERichEdit is a descendent of TRichEdit with support for RichEdit 8.0 functionality, including:
Enhanced text and paragraph formatting
Get and set rich text by property (RTFText property)
Automatic hover toolbar when editing text (AutoToolbar property)
Automatic customizable popup menu (if you do not assign your own)
Keyboard shortcuts built-in
Import and export to PDF and Microsoft Word, if available (ImportFromWord/ExportToWord methods)
Support for embedded images and objects
Insertion and editing of tables
Paint formatted text to a TBitmap or TIEBitmap (PaintTo method)
Enhanced Find and Replace
Multi-level undo
Spell checking
Automatic URL detection (AutoURLDetect property)
Bidirectional support



Note: Do not use IERichEdit1.Lines.Add(...); use AddLine or AddFormattedText


Keyboard Shortcuts

The default keyboard shortcuts are as follows:
Description Type Shortcut
Cut to Clipboard iesCut Ctrl+X
Copy to Clipboard iesCopy Ctrl+C
Paste from Clipboard iesPaste Ctrl+V
Align text left iesLeftAlign Ctrl+L
Center text iesCenterAlign Ctrl+E
Align text right iesRightAlign Ctrl+R
Justify text iesJustified Ctrl+J
Apply bold formatting iesBold Ctrl+B
Apply italic formatting iesItalic Ctrl+I
Apply underline formatting iesUnderline Ctrl+U
Open the Font dialog box iesFontSelect Ctrl+D
Removes all formatting from selection iesClearFormatting Ctrl+Space
Decrease the size of the font iesDecreaseFontSize Ctrl+Comma
Increase the size of the font iesIncreaseFontSize Ctrl+Period
Show Find dialog iesFind Ctrl+F
Find Next iesFindNext Shift+F4
Show Replace dialog iesReplace Ctrl+H
Select all text iesSelectAll Ctrl+A
Single line spacing - Ctrl+1
Double line spacing - Ctrl+2
1.5 line spacing - Ctrl+5

Demos


Demo  Demos\Other\RichEdit\RichEdit.dpr
Demo  Demos\Actions\Actions_IERichEdit\RichEditActions.dpr

Examples


// Set plain text in Editor
IERichEdit1.Text := 'Some Text';

// Set rich text in Editor
IERichEdit1.RTFText := #123'\rtf1\ansi\ansicpg1252\deff0'#123'\fonttbl'#123'\f0\fnil\fcharset0 Tahoma;'#125#125'\viewkind4\uc1\pard\lang1033\b\f0\fs24 ImageEn!\b0\par'#125;

// Show a hover toolbar when editing text
IEGlobalSettings().RichEditorToolbar.Position := iepAbove;
IERichEdit1.AutoToolbar  := True;



// Hide buttons for Bullets and Numbering
IEGlobalSettings().RichEditorToolbar.Buttons := IEGlobalSettings().RichEditorToolbar.Buttons - [irbRichEditBullets];

// Center the current paragraph
IERichEdit1.Paragraph.Alignment := paCenter;

// Bold the selected text
IERichEdit1.SelAttributes.Bold := True;

// Import a Word document
IERichEdit1.ImportFromWord( 'D:\MyDoc.docx' );

// Export to PDF
IERichEdit1.ExportToWord( 'D:\MyDoc.pdf' );

// Insert a web link
IERichEdit1.InsertLink( 'http://www.ImageEn.com', 'ImageEn Web Site' );

// Paint rich editor content to TImageEnView
const
  Text_Margin = 30;
var
  bmp : TIEBitmap;
  imgW, imgH, textW, textH: Integer;
  textRect: TRect;
begin
  imgW  := ImageEnView1.Width;
  imgH  := ImageEnView1.Height;
  textW := imgW - 2 * Text_Margin;

  // Calc height of text at this width
  textH := IERichEdit1.TextHeight( 0, textW );

  textRect := Rect( Text_Margin,
                    Text_Margin,
                    Text_Margin + textW,
                    Text_Margin + textH );

  bmp := TIEBitmap.Create;
  try
    bmp.width  := imgW;
    bmp.height := imgH;

    // Load an image to use as background?
    if not ( chkUseEditorBackground.checked or chkEnableAlpha.checked ) then
      bmp.LoadFromFile('D:\TextBackground.jpg');

    IERichEdit1.PaintTo( bmp, textRect, iehLeft, ievTop, chkUseEditorBackground.checked, chkEnableAlpha.checked );

    ImageEnView1.Assign(bmp);
  finally
    bmp.Free;
  end;

// Paint rich editor content to TImage
const
  Text_Margin = 30;
var
  bmp: TBitmap;
  imgW, imgH, textW, textH: Integer;
  textRect: TRect;
begin
  imgW  := Image1.Width;
  imgH  := Image1.Height;
  textW := imgW - 2 * Text_Margin;

  // Calc height of text at this width
  textH := IERichEdit1.TextHeight( 0, textW );

  textRect := Rect( Text_Margin,
                    Text_Margin,
                    Text_Margin + textW,
                    Text_Margin + textH );

  bmp := TBitmap.Create;
  try
    bmp.width  := imgW;
    bmp.height := imgH;

    // Load an image to use as background?
    if not chkUseEditorBackground.checked then
      bmp.LoadFromFile('D:\TextBackground.bmp');

    IERichEdit1.PaintTo( bmp, textRect, iehLeft, ievTop, chkUseEditorBackground.checked );

    Image1.Picture.Assign(bmp);
  finally
    bmp.Free;
  end;
end;

// Output an RTF file as an image
const
  Out_Width   = 500;
  Out_Height  = 800;
  Text_Margin = 20;
var
  re : TIERichEdit;
  bmp: TIEBitmap;
  textRect: TRect;
begin
  bmp := TIEBitmap.Create;
  re := TIERichEdit.CreateParented(HWND(HWND_MESSAGE));
  try
    re.Visible  := False;
    re.WordWrap := False;
    re.OpenFromFile( 'D:\RTF Document.rtf' );

    bmp.width  := Out_Width;
    bmp.height := Out_Height;

    textRect := Rect( Text_Margin,
                      Text_Margin,
                      Out_Width - Text_Margin,
                      Out_Height - Text_Margin );

    re.PaintTo( bmp, textRect, iehCenter, ievCenter, True );

    bmp.SaveToFile('D:\RtfImage.jpeg' );
  finally
    bmp.Free;
    re.Free;
  end;
end;

Methods and Properties


General
Public Method  AddLine
Public Property  AdvancedTypography
Published Property  AllowGutterSelection
Published Property  AutoURLDetect
Published Property  AutoToolbar
Public Property  CanPaste
Public Method  CharFromPos
Public Method  Clear
Public Method  GetCharPos
Public Method  GetLineIndex
Public Method  GetLineLength
Public Method  GetSelection
Public Method  GetTextRange
Published Property  HideScrollBars
Published Property  HideSelection
Published Property  KeyboardShortcuts
Public Method  InsertLink
Published Property  LanguageOptions
Public Method  LineFromChar
Published Property  OLEDragDrop
Public Method  PaintTo
Public Method  PasteAsPlainText
Public Property  PopupMenuAuto
Public Property  ReadOnly
Public Property  RichEditVersion
Public Method  SelectAll
Public Property  SelectionTypes
Public Property  SelLength
Public Property  SelStart
Public Property  SelText
Public Property  SelRTFText
Public Method  SetSelection
Public Method  SetSelectionAsLink
Published Property  SpellChecking
Public Method  TextHeight
Public Method  TextSize
Public Method  TextWidth
Public Method  WordAtCursor
Published Property  WordSelection
Published Property  Zoom

Input/Output
Public Method  CanImportExport
Public Method  ExportToWord
Public Property  Filename
Public Method  ImportFromWord
Public Method  OpenFromFile
Public Method  PromptToOpen
Public Method  PromptToSave
Public Method  SaveToFile

Formatting
Public Method  AddFormattedText
Public Property  DefAttributes
Public Method  InsertFormattedText
Public Property  Paragraph
Public Method  PromptForColor
Public Method  PromptForFont
Public Method  RemoveCurrentFormatting
Public Property  SelAttributes
Public Property  WordAttributes
Published Property  RTFText

Find and Replace
Public Method  CanFindNext
Public Method  FindDialog
Public Method  FindNext
Public Method  FindText
Public Method  ReplaceDialog

Undo/Redo
Public Property  CanRedo
Public Property  CanUndo
Public Method  ClearUndo
Public Method  Redo
Public Property  RedoName
Public Method  Undo
Public Property  UndoName
Public Property  UndoOnReplace
Published Property  UndoLimit

Text Methods
Public Method  Cut
Public Method  Copy
Public Method  Paste
Public Method  Delete
Public Method  SelectAll
Public Method  Print

Table Methods
Public Method  InsertTable
Public Method  GetTableProperties
Public Method  SetTableProperties

OLE Objects
Published Property  AllowObjects
Public Property  AllowInPlace
Public Method  CloseActiveObject
Public Method  InsertImage
Public Method  InsertLinkToFile
Public Method  InsertObjectDialog
Public Method  InsertObjectFromFile
Public Method  ObjectPropertiesDialog
Public Method  PasteSpecialDialog
Public Method  SaveSelectedImage


Events

Event  OnCloseFindDialog
Event  OnDragAllowed
Event  OnGetDragDropEffect
Event  OnQueryAcceptData
Event  OnTextNotFound
Event  OnURLClick
Event  OnURLHover