[Example] How to display a placeholder text for empty editor

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 15544
Joined: Sat Aug 27, 2005 10:28 am

[Example] How to display a placeholder text for empty editor

Post by Sergey Tkachenko »

There is no built-in property for displaying a text hint when TRichViewEdit is empty (we are considering to add it in future updates).
But you can implement it using OnPaint event:

Code: Select all

procedure TForm3.RichViewEdit1Paint(Sender: TCustomRichView; ACanvas: TCanvas;
  Prepaint: Boolean);
  X, Y: Integer;
  if not PrePaint and (Sender.ItemCount = 1) and (Sender.GetItemStyle(0) >= 0) and
    (Sender.GetItemText(0) = '') then
    Sender.GetItemClientCoords(0, X, Y);
    ACanvas.Font.Name := 'Tahoma';
    ACanvas.Font.Charset := DEFAULT_CHARSET;
    ACanvas.Font.Color := clGrayText;
    ACanvas.Font.Style := [];
    ACanvas.Font.Size := Sender.Style.TextStyles[Sender.GetItemStyle(0)].Size;
    ACanvas.Brush.Style := bsClear;
    SetTextAlign(ACanvas.Handle, TA_LEFT or TA_TOP);
    ACanvas.TextOut(X, Y, 'Please write something...');
Post Reply