text on the background

General TRichView support forum. Please post your questions here
Post Reply
adamrich
Posts: 35
Joined: Sun Feb 19, 2006 1:55 pm

text on the background

Post by adamrich »

Hello,

I'm trying to add few lines messages (text) on the RichViewEdit1 background instead of image, but when user start typing the background text need to be gone, just like some user forums uses CSS :)

I need that only on the new document (not already saved document)

Thank you
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: text on the background

Post by Sergey Tkachenko »

Do you want to display some text when the editor is empty?
adamrich
Posts: 35
Joined: Sun Feb 19, 2006 1:55 pm

Re: text on the background

Post by adamrich »

Yes please, only when empty

Thank you so much
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: text on the background

Post by Sergey Tkachenko »

There is no built-in property for this feature. But you can use OnPaint event:

Code: Select all

procedure TForm3.RichViewEdit1Paint(Sender: TCustomRichView; ACanvas: TCanvas;
  Prepaint: Boolean);
var
  X, Y: Integer;
begin
  if not PrePaint and (Sender.ItemCount = 1) and (Sender.GetItemStyle(0) >= 0) and
    (Sender.GetItemText(0) = '') then
  begin
    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...');
  end;
end;
adamrich
Posts: 35
Joined: Sun Feb 19, 2006 1:55 pm

Re: text on the background

Post by adamrich »

Thank you, you are awesome man!
As always I appreciate your superb support, you never let your user down, best support ever.

Thanks again
Post Reply