Disappearing Drag Box in Windows

I am trying to draw a drag box in a canvas as I click and drag to select a particular area. I am doing this by redrawing four lines in the paint method.
This works fine in MacOS but does not work in Windows. Any pointers please ?

Can you post a little demo project showing just the problem?

I have created a sample project. Can you please guide me how to post the project ?

One easy way could be a shared Google Drive Folder.

Draw your content to a buffer and in the paint even just draw that buffer picture and the 4 lines. DONT recreate the full content every single mousemove.

Looking ok is not the same as working fine. Drawing everty time the mouse moves you prolly going to max some cpu cores.


The paint event is to PAINT things in the canvas, not to move other controls around.

I just checked the DesktopCanvas.Paint Event Description in the LR, and as surprising as it is, nothing is said about its use…

There is not a single line about the use of “g” outside of the Event !

DesktopCanvas.Paint Event

It seems that you have to know the “common base knowledge” before using the “DesktopCanvas.Paint Event”.

Here’s a tutorial that explain some stuff youc an do with the Paint Event:

I first drew the lines in the MouseDrag event of the Canvas. The lines were ok in Mac but did not show up in Windows. It was then that I tried to put it in the Paint event just to see if it would work in Mac and Windows, but the result was the same. I am unable to understand why.
I now tried to draw the lines with the g.DrawLine
Now they show up both in Mac and Windows

You would probably get a faster drawing by using Drawrectangle rather than 4 lines.

Strange since there is no g (Graphics) available for painting (or drawing) in MouseDrag:

To learn how to draw something in a DesktopCanvas, Look the LR: DesktopCanvas.Paint

You will find there plenty examples to achieve this goal.

I’m a little confused, that’s a project I made a long time ago.