Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 912009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:18:29+00:00 2026-05-15T17:18:29+00:00

I need to write some text to a paintbox, and I do it in

  • 0

I need to write some text to a paintbox, and I do it in the OnPaint event. When I set the fontsize twice in the method, the OnPaint-event is called repeatedly.

To see for yourself, try this:

  1. Create a new VCL Forms application
  2. Place a paintbox on the form
  3. Put the following code in the OnPaint-event:
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  PaintBox1.Canvas.MoveTo(random(PaintBox1.Width),random(PaintBox1.Height));
  PaintBox1.Canvas.LineTo(random(PaintBox1.Width),random(PaintBox1.Height));

  PaintBox1.Font.Size := 10; 
  PaintBox1.Font.Size := 12; 
end;

When you run the application you will see a line “jumping” around on the paintbox. However, if you remove one or both of the lines setting the fontsize, you will see a single, stationary line.

Why does this happen, and what can I do to work around it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:18:30+00:00Added an answer on May 15, 2026 at 5:18 pm

    Set PaintBox1.Canvas.Font.Size instead of PaintBox1.Font.Size and your problem will be solved.

    As for why it happens: Changing the font property of a control will cause it to be invalidated and redraw, and doing this in the event that does the redrawing causes an infinite loop. Luckily paint events are synthesized and have lower priority than other messages, otherwise your program would hang.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI. I need to write some text over a custom button. So I subclassed
I have some text to write to the Windows console that I need to
I have some text below called (16 Courses). I need to hide only this
I need to create a function in JavaScript, that will write some text (which
I need to write some fixed-width font (i.e Courier New or Consolas) text to
I need to write a simple terminal-based program that should, Read some text from
I need to write some text over google maps image. I try lot off
I need to create/append a text file and write some data in that. When
I need to write some text rotated by 90 degrees. I first tried with
I need to open a file to write some text to it, is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.