B4J Question Load two layouts, is it possible (i.e. two seperate windows) (Solved)

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I want to load two layouts where one would be transferred to my second monitor (this being an attached TV screen) and the information sent to it would be from the layout on the PC screen, I can do it in VB6 (good old vb6) but can't find a similar solution in B4J

Is it possible, I would assume so
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Hi Colin,

I have an app in which I do that. I can't remember how I came across this method, but I expect it was via this community.

I can't vouch for the quality of the code, but the relevant part of the Main module code is:

B4X:
Sub AppStart (Form2 As Form, Args() As String)
    Display.Show   
    MainForm = Form2
    MainForm.SetFormStyle("UNIFIED")
    MainForm.Title = title
    MainForm.Icon = fx.LoadImage(File.DirAssets,"BDSConsulting.png")
    MainForm.RootPane.LoadLayout("Form2") 'Load the layout file.
    MainForm.Show    


End Sub

Sub MainForm_CloseRequest (EventData As Event)
    Display.DisplayForm.Close
End Sub


Then the Display module code is:

B4X:
'Static code module
Sub Process_Globals
    Public DisplayForm As Form

    Private ox, oy As Double
End Sub

Public Sub Show
    If DisplayForm.IsInitialized = False Then
        DisplayForm.Initialize("DisplayForm", 1366, 768)
        DisplayForm.RootPane.LoadLayout("Form1")
        DisplayForm.SetFormStyle("UNDECORATED")
        DisplayForm.Title = Main.title & " - Display"
        DisplayForm.Icon = Main.fx.LoadImage(File.DirAssets,"monitor.gif")

        DisplayForm.WindowWidth = Main.fx.PrimaryScreen.MaxX - Main.fx.PrimaryScreen.MinX
        DisplayForm.WindowLeft = Main.fx.PrimaryScreen.MinX
        DisplayForm.WindowHeight = Main.fx.PrimaryScreen.MaxY - Main.fx.PrimaryScreen.MinY
        DisplayForm.WindowTop = Main.fx.PrimaryScreen.MinY
        
        Dim jmf As JavaObject = DisplayForm
        Dim stage As JavaObject = jmf.GetField("stage")
        stage.RunMethod("setFullScreen", Array As Object(True))
        
        DisplayForm.Show
    End If
End Sub

Private Sub DisplayForm_CloseRequest (EventData As Event)
    Main.MainForm.Close
End Sub

Sub DisplayForm_MousePressed (EventData As MouseEvent)
    ox = EventData.X
    oy = EventData.Y
End Sub

Sub DisplayForm_MouseDragged (EventData As MouseEvent)
    Dim jo As JavaObject = EventData
    DisplayForm.WindowLeft = jo.RunMethod("getScreenX", Null) - ox
    DisplayForm.WindowTop = jo.RunMethod("getScreenY", Null) - oy
End Sub

This allows you to drag the second (fullscreen) layout to a second monitor and closing either form closes both.

I hope that's useful.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Hi Colin,

I have an app in which I do that. I can't remember how I came across this method, but I expect it was via this community.

I can't vouch for the quality of the code, but the relevant part of the Main module code is:

This allows you to drag the second (fullscreen) layout to a second monitor and closing either form closes both.

I hope that's useful.

Hi, thank you very much, it worked a treat, a few minor amendments, given I was calling Display from another module and problem sorted. Thanks again
 
Upvote 0
Top