You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Overlay/Controls/Button/Button without plugin
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control ButtonMBS1 Inherits MyButton
ControlInstance ButtonMBS1 Inherits MyButton
EventHandler Sub Action(x as integer, y as integer)
dim d as new date
Title="Last click: "+d.LongTime
End EventHandler
End Control
Control ButtonMBS2 Inherits MyButton
ControlInstance ButtonMBS2 Inherits MyButton
EventHandler Sub Action(x as integer, y as integer)
dim d as new date
Title="Last click: "+d.LongTime
End EventHandler
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyButton Inherits Canvas
ComputedProperty Sticky As Boolean
Sub Set()
mSticky = value
update
End Set
Sub Get()
return mSticky
End Get
End ComputedProperty
ComputedProperty Toggle As Boolean
Sub Set()
mToggle = value
update
End Set
Sub Get()
return mToggle
End Get
End ComputedProperty
ComputedProperty Value As Boolean
Sub Set()
mValue = value
update
End Set
Sub Get()
return mValue
End Get
End ComputedProperty
Event Action(x as integer, y as integer)
End Event
Event MouseDown(x as integer, y as integer)
End Event
Event MouseDrag(x as integer, y as integer)
End Event
Event MouseEnter()
End Event
Event MouseExit()
End Event
Event MouseUp(x as integer, y as integer)
End Event
EventHandler Sub Activate()
active = true
update
End EventHandler
EventHandler Sub Deactivate()
active = false
update
End EventHandler
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean
pressed = true
update
RaiseEvent MouseDown(x,y)
Return true
End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer)
RaiseEvent MouseDrag(x,y)
End EventHandler
EventHandler Sub MouseEnter()
RaiseEvent MouseEnter
MouseOver = true
update
End EventHandler
EventHandler Sub MouseExit()
RaiseEvent MouseExit
MouseOver = false
update
End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer)
pressed = false
update
RaiseEvent MouseUp(x,y)
RaiseEvent Action(x,y)
End EventHandler
EventHandler Sub Open()
active = true
End EventHandler
Sub update()
if active and enabled then
if pressed then
if mouseover and ImagePressedMouseOver <>nil then
backdrop = ImagePressedMouseOver
else
backdrop = ImagePressed
end if
else // not pressed
if MouseOver and ImageMouseOver<>nil then
backdrop = ImageMouseOver
else
backdrop = ImageNormal
end if
end if
else // disabled
if pressed and ImagePressedDisabled<>nil then
backdrop = ImagePressedDisabled
else // not pressed
backdrop = ImageDisabled
end if
end if
End Sub
Note "Note"
Property ImageDisabled As Picture
Property ImageMouseOver As Picture
Property ImageNormal As Picture
Property ImagePressed As Picture
Property ImagePressedDisabled As Picture
Property ImagePressedMouseOver As Picture
Property Private MouseOver As Boolean
Property Private Pressed As Boolean
Property Private active As Boolean
Property Private mSticky As Boolean
Property Private mToggle As Boolean
Property Private mValue As Boolean
End Class