I have a number of DesktopCanvas controls acting as buttons. I indicate “button pressed” by changing colors. When users mouse down but then drag the cursor off the control before releasing, that cancels the “button press”. This works fine, but I need the button’s color to change back to “unpressed” as soon as the cursor exits the control, and it just isn’t working, only changing to “unpressed” upon releasing the mouse button. The below code uses timers for a couple different purposes, but the color change also doesn’t happen for controls that don’t use a timer.
Sub Paint(g As Graphics, areas() As Rect)
If (Me.Name = MouseOverXY) And Not(EStop_Pressed) Then
g.DrawingColor = Color.Blue
Else
g.DrawingColor = Color.White
End If
g.FillRoundRectangle(0, 0, g.Width, g.Height, 10, 10)
If (Me.Name = MouseDownXY) And Not(EStop_Pressed) Then
g.DrawingColor = Color.Green
Else
g.DrawingColor = Color.Orange
End If
g.FillRoundRectangle(3, 3, g.Width - 6, g.Height - 6, 10, 10)
g.DrawingColor = Color.Black
g.DrawRoundRectangle(0, 0, g.Width, g.Height, 10, 10)
g.DrawRoundRectangle(3, 3, g.Width - 6, g.Height - 6, 10, 10)
g.FontSize = 28
g.DrawText("X+", 5, 32)
End Sub
Sub MouseEnter()
If Not(EStop_Pressed) Then
MouseOverXY = Me.Name
Me.Refresh
End If
End Sub
Sub MouseExit()
'code goes here to stop movement
MouseOverXY = ""
Me.Refresh
End Sub
Function MouseDown(x As Integer, y As Integer) As Boolean
If Not(EStop_Pressed) Then
XSpeed_Going = ""
MouseDownXY = Me.Name
bump = True
TimerBump.RunMode = Timer.RunModes.Single
SimStep = 1
TimerSim.Period = Slider_Jog_XSpeed.Value
TimerSim.RunMode = Timer.RunModes.Multiple
Me.Refresh
End If
Return True
End Function
Sub MouseUp(x As Integer, y As Integer)
MouseDownXY = ""
TimerBump.RunMode = Timer.RunModes.Off
TimerSim.RunMode = Timer.RunModes.Off
bump = False
Me.Refresh
End Sub
Sub DragExit(obj As DragItem, action As DragItem.Types)
MouseDownXY = ""
MouseOverXY = ""
Me.Refresh
TimerBump.RunMode = Timer.RunModes.Off
End Sub
Function DragEnter(obj As DragItem, action As DragItem.Types) As Boolean
MouseDownXY = Me.Name
MouseOverXY = Me.Name
Me.Refresh
TimerBump.RunMode = Timer.RunModes.Off
End Function