B4J Code Snippet How to set "MainForm" both as Utility and as Transparent

Hi guys,

Well, the title is kind of misleading...
A form cannot be styled to be BOTH as UTILITY and as TRANSPARENT...
So I found a little workaround ;)

B4X:
#Region Project Attributes
    #MainFormWidth: 10
    #MainFormHeight: 10
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private MyTray As SystemTray
    Private MyTrayIcon As TrayIcon
    Private MyTrayIconImage As Image
    Private MenuItems() As String
    Private LauncherTimer As Timer
    Private MyLauncher As Launcher
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UTILITY") 'Prevents from appearing in the taskbar
   
    'Providing a way to close the app
    MyTray.Initialize
    MyTrayIconImage  = fx.LoadImage(File.DirAssets,"1.png")
    MenuItems = Array As String("Exit B4X-Launcher")
    MyTrayIcon.Initialize("MyTray",MyTrayIconImage,MenuItems)
    MyTray.AddTrayIcon(MyTrayIcon)
   
    'we place the main form way outside the visible area
    MainForm.WindowTop = -1000

    'we set a timer to call the "other main form" after this one is shown
    LauncherTimer.Initialize("LauncherStart", 200)
    LauncherTimer.Enabled = True

    MainForm.Show
End Sub

Sub MyTray_MenuClick (Text As String)
    Select Text
        Case "Exit Launcher"
            MyTray.RemoveTrayIcon(MyTrayIcon)
            ExitApplication
    End Select
End Sub

Private Sub LauncherStart_Tick
    LauncherTimer.Enabled = False
    MyLauncher.Initialize(MainForm) 'this is the "NewMainForm" class, and we pass MainForm to be then set as the owner
End Sub

The class code is as simple as can be, and is here only to give a kick start..
B4X:
Public Sub Initialize(Owner As Form)
    LauncherForm.Initialize("",300,400)
    LauncherForm.SetFormStyle("TRANSPARENT")
    LauncherForm.BackColor = fx.Colors.Transparent
    LauncherForm.SetOwner(Owner)
    LauncherForm.Show
End Sub
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I found another solution to the Java icon showing in the taskbar. Since the icon can be changed it does not really matter if it's visible or not.
Cableguy this one is for you *Drumroll* :)

B4X:
MainForm.Icon = fx.LoadImage(File.DirAssets, "taskbarlogo.png")
 

Cableguy

Expert
Licensed User
Longtime User
What I wanted to achieve is a complete different thing... I wanted to hide that taskbar icon AND still having an UNDECORATED TRANSPARENT form...

But it's nice to know we can change the icon in code
 
Top