[Solved] OnPaint on Frame lazarus / 31-LCL ---------------------------------------------------------------------- Edson · 2014-03-12 18:38 I know how to implement the constructor and destructor on a Frame. But, How can I implement the OnPaint() event, on a frame. I have override this: Code: [Select]procedure TMyFrame.PaintWindow(DC: HDC); begin   inherited PaintWindow(DC);   {redraw something with Self.Canvas} end; But nothing is drawing when the form appears. It's like 'Self.Canvas' doesn't work on the PaintWindow() event. What is the correct way for to implement the OnPaint event on a Frame? Thanks. ---------------------------------------------------------------------- taazz · 2014-03-12 19:00 Why TFrame? Why not a component that is designed to be painted on like tpanel or TPaintBox or even TScrollBox. In any case it is better to override the Paint method (which only calls the onpaint event internaly) instead of the paintwindow, as far as I can see the the onpaint event is public in TFrame this means that can be used from code but can't be seen in the object inspector. EDIT: Forgot to say that if you draw anything where your comment is it should be shown at run time. forget it my bad use the paint instead. ---------------------------------------------------------------------- Edson · 2014-03-12 20:46 Quote from: taazz on March 12, 2014, 08:00:08 pmWhy TFrame? Why not a component that is designed to be painted on like tpanel or TPaintBox or even TScrollBox. I was looking for a mean for to encapsulate the code of a graphic editor. All this code is complex and I prefer to put all them on a separate file from the form. Moreover I can include it, in other forms. Quote from: taazz on March 12, 2014, 08:00:08 pmIn any case it is better to override the Paint method (which only calls the onpaint event internaly) instead of the paintwindow Is it an event?. I only see the  Method Paint(). I need the event what is fired when Windows shows the frame or when it is necessary to repaint the frame. Finally, I have included a TPaintBox in the Frame, in order to have the OnPaint event working. I wanted to draw directly on the canvas of the frame, but it seems to be some complicated. ---------------------------------------------------------------------- taazz · 2014-03-12 20:59 Why is the PaintWindow you used an event? No! if you need an onpaint event then you can write one and assign it at run time but why not override the Paint method instead it will do the same thing with a jump less. ---------------------------------------------------------------------- howardpc · 2014-03-12 22:44 Something along these lines: Code: [Select]unit framePaintUnit; {$mode objfpc}{$H+} interface uses   Forms, Graphics; type   { TmyFrame }   TmyFrame = class(TFrame)   protected     procedure Paint; override;   end; implementation {$R *.lfm} { TmyFrame } procedure TmyFrame.Paint; begin   with Canvas do begin     Brush.Color:=Color;     FillRect(ClientRect);     Brush.Color:=clDkGray;     FrameRect(ClientRect);     Brush.Color:=Color;     TextOut(20,20,'This is a ''self-drawn'' frame.');     TextOut(20,35,'You''ll see this text provided no controls');     TextOut(20,50,'dropped on the frame obscure it.');   end;   inherited Paint; end; end. ---------------------------------------------------------------------- Edson · 2014-03-13 04:21 That code works. I was looking for one example with OnPaint event with no Success. Thanks guys.