B4J Question How to Bring a Minimized Form to Front?

xulihang

Active Member
Licensed User
Longtime User
I am trying the following code:

B4X:
Dim value As Boolean = frm.AlwaysOnTop
wait for (DoCapture) Complete (done As Object)
frm.AlwaysOnTop = True
sleep(0)
frm.AlwaysOnTop = value

But it does not work.
 
Solution
Try this code
B4X:
wait for (DoCapture) Complete (done As Object)
frm.As(JavaObject).GetField("stage").As(JavaObject).RunMethod("setIconified",Array As Object(False))

Cableguy

Expert
Licensed User
Longtime User
A minimized (iconified) form is NOT visible, thus it cannot be "on top" of anything!
You need to first make it visible (like restore or maximized), and only then, when visible, make it always on top.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Try this code
B4X:
wait for (DoCapture) Complete (done As Object)
frm.As(JavaObject).GetField("stage").As(JavaObject).RunMethod("setIconified",Array As Object(False))
 
Upvote 1
Solution

Cableguy

Expert
Licensed User
Longtime User
RunMethod("setIconified",Array As Object(False))
that will work because you will be making the form visible again (restore => iconified = false)
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Both ways...
B.T.W. By setting .AlwaysOnTop to true, the form will be restored on top.
@teddybear shows in #4 how to put the Sub in a one liner.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.AlwaysOnTop = True
    MainForm.Show
   
    Dim auxForm As Form
    auxForm.Initialize("", 1000, 1000)
    auxForm.Show
   
End Sub

Sub Button1_Click
    IconifyForm(MainForm)
    Sleep(3000)  
    RestoreForm(MainForm)
End Sub

Public Sub RestoreForm(Frm As Form)
    Dim jForm As JavaObject = Frm
    Dim stage As JavaObject = jForm.GetField("stage")
    stage.RunMethod("setIconified", Array As Object(False))
End Sub

Public Sub IconifyForm(Frm As Form)
    Dim jForm As JavaObject = Frm
    Dim stage As JavaObject = jForm.GetField("stage")
    stage.RunMethod("setIconified", Array As Object(True))
End Sub
 
Upvote 0
Top