Firemonkey tEdit OnPaint

  

I have a tEdit and I want to paint it’s rect with a different set of Fill and Stroke colors. I coded as follows:

procedure TForm1.FormCreate (Sender: TObject);
begin
Edit1.OnPaint := HandleEditPaint;
end;

procedure TForm1.HandleEditPaint (Sender: tObject; Canvas: tCanvas; const aRect: tRectF);
begin
Canvas.BeginScene;
Canvas.Fill .Color := TAlphaColorRec.Aqua;
Canvas.Fill .Kind := TBrushKind.bkSolid;
Canvas.Stroke.Color := TAlphaColorRec.Red;
Canvas.Stroke.Kind := TBrushKind.bkSolid;
Canvas.FillRect (aRect, 0, 0, AllCorners, 1, TCornerType.Bevel);
Canvas.DrawRect (aRect, 0, 0, AllCorners, 1, TCornerType.Bevel);
Canvas.EndScene;
end;

It paints the control’s rect properly, but it cannot be focused because when clicking on the Control, it enters in a loop that trigger’s HandleEditPaint non stop. How can I avoid this to happen? I know that in painting the control’s rect, I must take care of the control’s text too, but I should concern about the mouse cursor either? Is there a way to achieve this behavior using styles?

Comments are closed.