Recent

Author Topic: Call onpaint method  (Read 13665 times)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Call onpaint method
« on: May 22, 2009, 12:48:04 pm »

Hi all,

How can i call any component's onpaint evet from procedure or function,
or not just onpaint any event?
Thanks

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Call onpaint method
« Reply #1 on: May 22, 2009, 01:04:47 pm »
Invalidate, Repaint or Refresh.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Call onpaint method
« Reply #2 on: May 22, 2009, 01:16:54 pm »

Is there any other method instead of these?
Thanks for the information.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Call onpaint method
« Reply #3 on: May 22, 2009, 03:02:40 pm »
Is there any other method instead of these?

Aren't these enough?

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Call onpaint method
« Reply #4 on: May 22, 2009, 06:42:23 pm »

No, these are enough.
Bu I just want to know is there any tricky way?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Call onpaint method
« Reply #5 on: May 22, 2009, 07:02:04 pm »
Maybe you can use the win32 widgetset, it is more forgiving for painting outside the paint event.  ;)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Call onpaint method
« Reply #6 on: May 22, 2009, 07:40:51 pm »

I have tested the following source code, here in this code the onpaint event fired from the Form, but in here the paint event doesnt work whenever drag the form the paint event triggered.
So I read an article written like this:

"This is the order of the initialization.
OnCreate -> OnShow -> OnActivate -> OnPaint -> OnResize -> OnPaint ... and so on.

OnPaint, OnResize
Events like OnPaint and OnResize are always called after the form is initially created, but are also called repeatedly. OnPaint occurs before any controls on the form are painted (use it for special painting on the form)."

Here is the question then if "use it for special painting on the form" is written why does the following code doesnt work properly.
Thanks
 
procedure TForm1.FormPaint(Sender: TObject);
var
  r:TRect;
begin
  r.TopLeft:=bevel1.ReadBounds.TopLeft;
  r.BottomRight:=bevel1.ReadBounds.BottomRight;

  Bevel1.Canvas.Pen.Color:=clRed;
  Bevel1.Canvas.Brush.Color:=clRed;
  Bevel1.Canvas.Rectangle(r);
  Bevel1.Canvas.FillRect(r);
end;


Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Call onpaint method
« Reply #7 on: May 22, 2009, 07:47:01 pm »
I still don't understand where the problem is. If I understood the textbook correctly, then this FormPaint code should rather be Bevel1's OnPaint code.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Call onpaint method
« Reply #8 on: May 22, 2009, 07:58:38 pm »

Yes mostly, but rather than Bevel's OnPaint event whenever the mentioned code put into the Form's OnPaint method this must be painted as well because of the written text or quote.
PS. Follow the bold red text.

"This is the order of the initialization.
OnCreate -> OnShow -> OnActivate -> OnPaint -> OnResize -> OnPaint ... and so on.

OnPaint, OnResize
Events like OnPaint and OnResize are always called after the form is initially created, but are also called repeatedly. OnPaint occurs before any controls on the form are painted (use it for special painting on the form)."

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Call onpaint method
« Reply #9 on: May 22, 2009, 08:12:34 pm »
That seems to be from a Delphi article and might not apply to the LCL.

Anyway, in the OnPaint event of a form, you may only paint on the Canvas of the form.
« Last Edit: May 22, 2009, 08:14:38 pm by Vincent Snijders »

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Call onpaint method
« Reply #10 on: May 22, 2009, 08:15:37 pm »

Yep you are right, it is a Delphi article.
here is the link
http://delphi.about.com/od/formsdialogs/a/delphiformlife.htm

So will apply in the near future or not apply, never. :)
Thanks for the dialog.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Call onpaint method
« Reply #11 on: May 22, 2009, 08:22:37 pm »
I think it applies:

OnPaint occurs before any controls on the form are painted (use it for special painting on the Form).

So, on the Form, and not on Bevel1.

 

TinyPortal © 2005-2018