Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Window Icon/Window Icon
This example is the version from Thu, 16th Nov 2016.
Project "Window Icon.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim file as FolderItem = FindFile("someicon.ico")
if file.Exists then
call self.SetWindowIconMBS(0, File, 0)
else
MsgBox "Icon file not found."
end if
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
dim p as Picture
dim m as Picture
// random colored circle image
p = New Picture(32,32,32)
p.Graphics.ForeColor=&c000000
p.Graphics.FillRect 0,0,32,32
p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256)
p.Graphics.Filloval 0,0,32,32
// circle mask
m = New Picture(32,32,32)
m.Graphics.ForeColor=&c000000 // transparent
m.Graphics.Fillrect 0,0,32,32
m.Graphics.ForeColor=&cFFFFFF // color
m.Graphics.Filloval 0,0,32,32
call self.SetWindowIconMBS(0,p,m)
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
dim p as Picture
dim m as Picture
// random colored circle image
p = New Picture(16,16,32)
p.Graphics.ForeColor=&c000000
p.Graphics.FillRect 0,0,16,16
p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256)
p.Graphics.Filloval 0,0,16,16
// circle mask
m = New Picture(16,16,32)
m.Graphics.ForeColor=&c000000 // transparent
m.Graphics.Fillrect 0,0,16,16
m.Graphics.ForeColor=&cFFFFFF // color
m.Graphics.Filloval 0,0,16,16
call self.SetWindowIconMBS(0,p,m)
End EventHandler
End Control
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS Win Plugin.