1

I have made a drawing on an FMX TPaintBox and I want to remove/delete the drawing from the TPaintBox when I click on a button, but how?

I have tried things like this to set the canvas to empty, but it's not working:

PaintBox1.Canvas := nil;

What I am doing now is I am hiding the whole TPaintBox component and pretending it is not there. But it would be better if I can empty it. I have also tried deleting the component from the form and then creating a new one if needed with code, but this is tricky.

1 Answer 1

3

Painting in a TPaintBox is not persistent. You have to redraw everything from scratch every time the OnPaint event is triggered. So, to clear the TPaintBox, simply call its InvalidateRect() or Repaint() method to trigger a repaint, and then don't draw anything in subsequent calls to its OnPaint event until you are ready to draw new things again.

I described this in my answer to your previous question.

Sign up to request clarification or add additional context in comments.

3 Comments

if i want to draw different things then i need more than one TPaintBox?
You need to be more specific. Draw different things that are shown at the same time? You can draw whatever you want on a single TPaintBox in a single OnPaint event. Or, different things one after the other? Simply draw one thing in OnPaint, and then later change what you draw in OnPaint.
No you don't need more than one PaintBox to draw multiple different things. All you need to do is write the OnPaint even in a way that it will paint what you need at the time you want. For instance you can write multiple procedures where one would draw one thing and other will draw some other thing. Then from OnPaint event you simply call the needed procedure, You would need some control variable that will tel your program which procedure to use thou.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.