I have a canvas, canvas1, in a window and I have these properties…
MouseXDown As Integer
MouseYDown As Integer
MouseXUp As Integer
MouseYUp As Integer
In the paint event of Canvas1 I have this…
Sub Paint(g As Graphics, areas() As REALbasic.Rect)
g.ForeColor=RGB(255,0,0)
g.PenHeight = 5
g.PenWidth = 5
g.Drawline(MouseXDown, MouseYDown, MouseXUp, MouseYUp)
Me.Invalidate
End Sub
When the app launch. if I click the mouse and then release it after dragging it I was expecting a red line to be displayed from MouseDown to MouseUp but I do not see that happening.
When the app launches, i see a 5x5 points red-filled circle.
Because the canvas image is not a picture… it dras completely in the paint event, and you only have these 4 variables.
If you want the lines to persist, you need an actual picture the same size as the canvas.
Draw on that.
In the Canvas paint event, draw the picture to the canvas graphics instead of drawing lines on it.
Or create an array of object2d objects to record each new set of points, and draw them all in the canvas paint event
What i am really trying to do is to make is a “screen marker” app, where the window is transparent and the user draws freehand lines to highlight a particular thing.
I know how to do the invisible window and invisible canvas.
1/ Grab the screen into a picture
2/Open your window full screen (search for Kiosk… may be useful)
3/In the paint event, paint the picture.
4/When the mouse is used to draw, draw on the picture
5/When the canvas paints, draw the amended picture
If you want to be able to undo the line, store the picture AND an amended copy so that you can take parts from the original grab and reset that part of the screen