# Canvas drawing

**URL:** <https://forum.xojo.com/t/canvas-drawing/62986>\
**Category:** Windows\
**Created:** [April 27, 2021, 12:29am UTC](https://forum.xojo.com/t/canvas-drawing/62986 "2021-04-27T00:29:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 27, 2021, 12:29am UTC](https://forum.xojo.com/t/canvas-drawing/62986/1 "2021-04-27T00:29:54Z")

</div>

Hi guys,  
I wanted to run it by you just in case somebody did something similar so I don’t have to reinvent the wheel. I want to draw a circle to mark the area when I click the mouse in a position of the car. I was reading some but quite don’t get it yet. Maybe someone has a sample project I can download to see or give me some pointers?

 ![image](https://forum.xojo.com/uploads/default/original/2X/a/adf9ef0786f7b972384c11f68067f6e27c4a2ae5.png)

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [April 27, 2021, 5:21am UTC](https://forum.xojo.com/t/canvas-drawing/62986/2 "2021-04-27T05:21:15Z")

</div>

Add 2 form-level integer variables called (eg)  
selected\_x and selected\_y  
of type integer,  
default values of -999 each

When the canvas PAINT event fires, you draw the car image.

If the selected\_x and selected\_y are NOT -999,  
draw a circle around the selected\_x,selected\_y co-ordinates  
using g.drawoval selected\_x,selected\_y, 10,10  
end if

When the mouse is clicked on the image, you detect the position in the mousedown event  
Store the x,y co-ordinates in selected\_x, selected\_y  
Then refresh the canvas

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 27, 2021, 12:52pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/3 "2021-04-27T12:52:05Z")

</div>

Thank you Jeff. That worked.  
Any way I can erase what i have drawn maybe by clicking on the area again? I looked it up and the last thing I saw was to reload the backdrop picture but that erases everything except for the last drawing.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [April 27, 2021, 1:40pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/4 "2021-04-27T13:40:29Z")

</div>

> [@Allen\_Arissa](#):
>
> Any way I can erase what i have drawn maybe by clicking on the area again?

You havent drawn anything permanent with my code  
if you no longer wanted the circle, set the co-ordinates back to -999

I suspect that you now have a long list of questions about how to create a full-on drawing package, rather just than the original question about how to draw a circle where you click.  
For example, the backdrop want mentioned in the original post.

So: what do you actually want to do?

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 27, 2021, 1:50pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/5 "2021-04-27T13:50:26Z")

</div>

The backdrop is the picture of the car outline I first posted. What I want the user to do is to click on the area(s) of the car and put a circle on it (which is what I did with your code). What I want is to be able for the user to erase the circle(s) should they changed their mind where they put the circle to begin with. I first though by clicking on a circle that is already drawn, if it exists, then remove it. Then I put a button to just erase everything and I though by reloading the backdrop, it would erase everything but the last circle stays there. I am sorry for all these questions, I tried to search without posting but it is still not clear to me.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [April 27, 2021, 2:31pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/6 "2021-04-27T14:31:36Z")

</div>

> [@Allen\_Arissa](#):
>
> What I want is to be able for the user to erase the circle(s) should they changed their mind where they put the circle to begin with. I first though by clicking on a circle that is already drawn, if it exists, then remove it. Then I put a button to just erase everything and I though by reloading the backdrop, it would erase everything but the last circle stays there

if you change the currentx and currenty properties when the user clicks, the circle will move to the new position  
If you dont want a circle (clearing it) , set the currentx and currenty values to -999  
the original answer does all that for you.

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 27, 2021, 4:08pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/7 "2021-04-27T16:08:48Z")

</div>

Now I understand. Working like a charm. Thank you Jeff for all your help. Much appreciated!

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 28, 2021, 2:23am UTC](https://forum.xojo.com/t/canvas-drawing/62986/8 "2021-04-28T02:23:16Z")

</div>

Im sorry Jeff, I thought I understood but I am missing something. I went to save the canvas with all the selected ovals I put but it only saved the backdrop and the last oval. I know I am missing something simple like process each oval I paint.

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 28, 2021, 2:29am UTC](https://forum.xojo.com/t/canvas-drawing/62986/9 "2021-04-28T02:29:45Z")

</div>

ps. reading on your response. Right now everytime I click on different area of the canvas, it doesnt erase the previous oval but instead adds another one which is what I want so the user can select different location on the car. Let me know if you want me to post a picture of how I want to save to .png or the codes.

---

<div class="post-metadata">

**Author:** ![Ivan\_Tellez](https://forum.xojo.com/letter_avatar_proxy/v4/letter/i/a9a28c/32.png) [@Ivan\_Tellez](https://forum.xojo.com/u/Ivan_Tellez)\
**Post date:** [April 28, 2021, 2:34am UTC](https://forum.xojo.com/t/canvas-drawing/62986/10 "2021-04-28T02:34:29Z")

</div>

Did you look at the examples in Xojo? there is one called **ObjectsInCanvas**

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [April 28, 2021, 5:14am UTC](https://forum.xojo.com/t/canvas-drawing/62986/11 "2021-04-28T05:14:45Z")

</div>

> [@Allen\_Arissa](#):
>
> I went to save the canvas with all the selected ovals

The original question

> I want to draw a circle to mark the area when I click the mouse in a position of the car.

and my answer, assume there is one circle.  
If you want several circles, you could just draw on the original image.

That doesnt allow you to **erase** , however, so you need to maintain both the original image plus a list of ‘circle positions’  
Erasing is a process of removing one of the items from the list of positions, then redrawing again.

It is time to look at the examples, because the requirement (as I expected) was more than you asked originally, and the examples contain a fuller worked solution for you.

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 28, 2021, 11:01am UTC](https://forum.xojo.com/t/canvas-drawing/62986/12 "2021-04-28T11:01:08Z")

</div>

Thank you Jeff and Ivan. I did check the examples but I will check them out again to see if i figure it out.

---

<div class="post-metadata">

**Author:** ![Pawel\_Soltysinski](https://forum.xojo.com/user_avatar/forum.xojo.com/pawel_soltysinski/32/23522_2.png) [@Pawel\_Soltysinski](https://forum.xojo.com/u/Pawel_Soltysinski)\
**Post date:** [April 28, 2021, 11:06am UTC](https://forum.xojo.com/t/canvas-drawing/62986/13 "2021-04-28T11:06:43Z")

</div>

automotive auto refinish market? looks familiar to one of my topics… 😉

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 28, 2021, 12:12pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/14 "2021-04-28T12:12:19Z")

</div>

Hi Pawel,  
Yes it is. They want to print out a sheet when the vehicle comes in showing where the damages are.

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 28, 2021, 4:39pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/15 "2021-04-28T16:39:38Z")

</div>

Hi Guys,  
I am almost there. I modified the ObjectsInCanvas example to something that could work for me. The only thing that I am stuck on is how to put the backdrop. I tried adding an object which is fine but when I tried to move a particular object, I can’t because the big object gets the focus. I have included a link with the source to see if anyone can help me. The ideal will be a backdrop (and is for the vehicle outline).

[https://drive.google.com/drive/folders/1HOXwcB5bwIUL1W\_JDx4yrC5iWGdp9MKi?usp=sharing](https://drive.google.com/drive/folders/1HOXwcB5bwIUL1W_JDx4yrC5iWGdp9MKi?usp=sharing)

Thanks again

---

<div class="post-metadata">

**Author:** ![Allen\_Arissa](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Allen\_Arissa](https://forum.xojo.com/u/Allen_Arissa)\
**Post date:** [April 29, 2021, 1:21pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/16 "2021-04-29T13:21:55Z")

</div>

I got it guys. Thank You

---

<div class="post-metadata">

**Author:** ![Aurelian\_N](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Aurelian\_N](https://forum.xojo.com/u/Aurelian_N)\
**Post date:** [January 20, 2024, 7:51pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/17 "2024-01-20T19:51:04Z")

</div>

@Allen_Arissa did you managed to fix that ? i tried accessing your link and it seems that it is not available anymore, i’m interested in something like this as well but me i need to move the objects in the canvas and then to store their coordinates.

thanks

---

<div class="post-metadata">

**Author:** ![RudolfJ](https://forum.xojo.com/user_avatar/forum.xojo.com/rudolfj/32/644_2.png) [@RudolfJ](https://forum.xojo.com/u/RudolfJ)\
**Post date:** [January 20, 2024, 8:34pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/18 "2024-01-20T20:34:28Z")

</div>

Hello Allen  
my Examble mit Pixmapshape

[https://www.dropbox.com/scl/fi/k4ntfebel6idindr2cl3p/pixmap-class-test.xojo\_binary\_project?rlkey=4apraayd6ecv1twvb08prhthg&dl=1](https://www.dropbox.com/scl/fi/k4ntfebel6idindr2cl3p/pixmap-class-test.xojo_binary_project?rlkey=4apraayd6ecv1twvb08prhthg&dl=1)

---

<div class="post-metadata">

**Author:** ![Aurelian\_N](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/b4bc9f/32.png) [@Aurelian\_N](https://forum.xojo.com/u/Aurelian_N)\
**Post date:** [January 20, 2024, 8:39pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/19 "2024-01-20T20:39:27Z")

</div>

Thanks a lot, that is apparently what i was looking for

Now i need to match my canvas with the paper and make sure that dot x on paper is same with the one on canvas.

Thanks again

---

<div class="post-metadata">

**Author:** ![Pawel\_Soltysinski](https://forum.xojo.com/user_avatar/forum.xojo.com/pawel_soltysinski/32/23522_2.png) [@Pawel\_Soltysinski](https://forum.xojo.com/u/Pawel_Soltysinski)\
**Post date:** [April 9, 2024, 6:37pm UTC](https://forum.xojo.com/t/canvas-drawing/62986/20 "2024-04-09T18:37:04Z")

</div>

a late reply but why not… I have the same problem few years ago - the body shop was able to mark “parts” of car body to declare total damage or partial damage (whether the part needs to be fully repainted / replaced or just partially painted). Combined with car make/model I had a database of surface areas and then - I could calculate approximate paint spendings. The ability to predict of costs / time of repair was nice thing to have 🙂

[Next page](https://forum.xojo.com/t/canvas-drawing/62986.md?page=2)
