I am trying to implement a simple line draw using the mouse on a canvas. The below code leaves artifacts on the canvas. I was expecting Canvas1.DrawLine(StartX,Starty,Endx,Endy,fx.Colors.White,10) in the MouseDragged to remove the existing line. It almost does but leaves artifacts.
Draw Line With Mouse On Canvas:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private DrawLine As Boolean
Private Canvas1 As Canvas
Private ToggleButton1 As ToggleButton
Private StartX As Double
Private Starty As Double
Private Endx As Double
Private Endy As Double
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("testdraw") 'Load the layout file.
MainForm.Show
Canvas1.DrawRect(0,0,Canvas1.Width,Canvas1.Height,fx.Colors.White,True,10)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Canvas1_MouseClicked (EventData As MouseEvent)
End Sub
Sub Canvas1_MouseMoved (EventData As MouseEvent)
End Sub
Sub Canvas1_MouseDragged (EventData As MouseEvent)
If ToggleButton1.Selected And DrawLine = True Then
Canvas1.DrawLine(StartX,Starty,Endx,Endy,fx.Colors.White,10)
Endx = EventData.X
Endy = EventData.Y
Canvas1.DrawLine(StartX,Starty,Endx,Endy,fx.Colors.Blue,10)
End If
End Sub
Sub Canvas1_MousePressed (EventData As MouseEvent)
If EventData.PrimaryButtonPressed Then
If ToggleButton1.Selected And DrawLine = False Then
DrawLine = True
StartX = EventData.X
Starty = EventData.Y
Endy = EventData.Y
Endx = EventData.X
Else
End If
End If
End Sub
Sub Canvas1_MouseReleased (EventData As MouseEvent)
If DrawLine = True Then
Canvas1.DrawLine(StartX,Starty,Endx,Endy,fx.Colors.White,10)
Endx = EventData.X
Endy = EventData.Y
Canvas1.DrawLine(StartX,Starty,Endx,Endy,fx.Colors.Blue,10)
DrawLine = False
End If
End Sub
Sub Canvas1_MouseEntered (EventData As MouseEvent)
End Sub
Sub Canvas1_MouseExited (EventData As MouseEvent)
End Sub
Sub Canvas1_FocusChanged (HasFocus As Boolean)
End Sub
Sub ToggleButton1_SelectedChange(Selected As Boolean)
End Sub
Project attached,