Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have form with picture in its background.(so I cant do methods that use filling background by color for erasing line).
I have drawing multiple lines with clicking bottoms and I need to clear some of them. I used drawline method.
also invalidate() or clear() doesn't work properly.
the below picture show what I explained, on clicking next bottom, the red circle lines should clear and new ones should draw.
q1.png - Google Drive[^]

What I have tried:

I have used invalidate() but it work with bog.
sometimes when clicking, the lines disappear.
Updated 20-Oct-22 8:32am
Richard MacCutchan 20-Oct-22 12:40pm    
Probably some secret error in your secret code. But since we cannot see any of it we cannot make any suggestions.
Dave Kreskowiak 20-Oct-22 13:19pm    
The generic answer to this problem is to invalidate the control you're drawing on so you can repaint everything, EXCEPT the line you're removing.

1 solution

Presumably, you are drawing directly onto the Image: if so, you can't "undo" lines even if you drew them because they become a permanent part of the picture - just as a child scrawling glasses and a moustache on your wedding photos with a biro makes permanent changes to it.

And the solutions to your problem are the same as for the wedding photo:
1) Replace the corrupted image with a fresh copy of the original, and draw the other lines back onto it.
2) Put a film (or sheet of glass) over the top of the photo so you can wipe it clean and draw the other lines back onto it. In C#, that means handling the Paint event for the display control, and every single time it is invalidated, you redraw the current set of lines. Then when you want to remove a line, you remove it from the "to draw" collection, and invalidate the control.
Share this answer
Ali Valizadegan 21-Oct-22 3:07am    
can you give a simple example code with two bottoms and a background image, when a bottom pressed a line appear and on press of other bottom the last line erase and new one draw and vise versa??
OriginalGriff 21-Oct-22 3:57am    
No, because I'm not here to do your job for you and I don't get paid for it either! :laugh:
You are a developer, and this isn't complicated: just think about exactly what you are trying to do, and read what I said again. It is pretty basic stuff!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900