How do I force a Form/Paintbox to update? [SOLVED] lazarus / 39-Graphics ---------------------------------------------------------------------- ad1mt · 2025-10-20 21:00 I am updating a paintbox on a form, from a paintbox.click procedure. But the form paintobx is not re-painted onscreen until an external event like key press or mouse click prompts it. I've tried calling paintbox.invalidate and form.invalidate but this does not prompt the form.paintbox to be re-painted onscreen. Is there any way to force this to happen? Or is there a way to create a fake mouse click or fake key press event? Thanks. ---------------------------------------------------------------------- Josh · 2025-10-20 21:07 you could try calling application.processmessages; if the message queue is operating the paintbox.repaint/invalidate should work,unless you have a tight loop not giving up time for the message queue. check your running processes, and see how much cpu your app is consuming. ---------------------------------------------------------------------- ad1mt · 2025-10-20 21:55 There are no background processes or threads. Here's a quick summary of what I'm doing... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PaintBox1Click(Sender: TObject);beginpaint_onto_paintbox(PaintB ox1);paintbox1.Invalidate;Form2.Visible:= TRUE;end; Then when form2 is closed with its close button, I expected form1.paintbox to be refreshed onscreen, but it isn't; it is waiting for an external form1 input event to prompt it to do the refresh. I know this because it refreshes onscreen as soon as I click on form1. I think what needs to happen is something like this... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PaintBox1Click(Sender: TObject);beginpaint_onto_paintbox(PaintB ox1);paintbox1.Invalidate;INSERT_MOUSE_CLICK_INTO_FORM1_MESSAGE_QUEUE; Form2.Visible:= TRUE;end; ---------------------------------------------------------------------- speter · 2025-10-20 22:09 Quote from: ad1mt on October 20, 2025, 11:55:48 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PaintBox1Click(Sender: TObject);beginpaint_onto_paintbox(PaintB ox1);paintbox1.Invalidate;Form2.Visible:= TRUE;end;I thought any drawing on the paintbox, *before* invalidate calls paintbox1.paint (or whatever the method is called); would be lost. Maybe move the "paint_onto_paintbox(PaintBox1)" code inside your on- paint event handler... cheers S. ---------------------------------------------------------------------- Josh · 2025-10-20 22:37 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i paint_onto_paintbox(PaintBox1);paintbox1.Invalidate; Makes no sense, you paintyourstuff on the paintbox, then by calling invalidate the paintbox redraws itself, wiping out your paint_onto_paintbox(PaintBox1); Any painting you want to do has to be in the OnPaint event of the paintbox if you want it tobe persistant. Then it will redraw itself if form invalidate/paint is called when a resize event etc. If you want to manually update it then just call paintbox1.repaint; Many things can cause a repaint to be triggered,most outof your normal control, putting your stuffin the onpaint events, keeps it persistant. The same applies to any control, you want to visually customize (timage,tpanel etc) , your code has to be in the onpaint event ---------------------------------------------------------------------- ad1mt · 2025-10-21 06:44 I found the problem. I was calling a second form, which sometimes required form1 to be refreshed. But I was calling the second form with form2.visible, when I should have used form2.showmodal, which stops form1 code from executing until form2 has closed.