In the showOn event I am trying to center the form on my extended monitor but the form is positioned at the top of the extended monitor.
The extended monitor height is 1080 and the WindowTop calculates to 140 but the form is at the top so it would seem the WindowTop is 0?
The extended monitor height is 1080 and the WindowTop calculates to 140 but the form is at the top so it would seem the WindowTop is 0?
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private btnFileDialog As Button
Private fc As FileChooser
Private f As String
Private ParsedData As Map
Private fx As JFX
Private MainForm As Form
Dim desktop(fx.Screens.Size) As Double
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
MainForm.Title = "Convert .fpl To *.fms"
Dim sc As List = fx.Screens
Dim cnt As Int = 0
For Each o As JavaObject In sc
Dim bounds As JavaObject = o.RunMethodjo("getBounds",Null)' required
Dim minX As Double = bounds.RunMethod("getMinX",Null)'required
Dim minY As Double = bounds.RunMethod("getMinY",Null)' optional
Dim width As Double = bounds.RunMethod("getWidth",Null)' optional
Dim height As Double = bounds.RunMethod("getHeight",Null)'optional
If cnt == 1 Then
Dim width1 As Double = bounds.RunMethod("getWidth",Null)' optional
Dim height1 As Double = bounds.RunMethod("getHeight",Null)'optional
End If
'Log($"Screen is ${width} x ${height} pixels"$)' optional
'Log($"minimum X: ${minX} minimum Y: ${minY}"$)' optional
desktop(cnt) = minX ' required
cnt = cnt + 1 ' required
Next
Log(cnt)
'MainForm.WindowHeight = 800
'MainForm.WindowWidth = 1200
'MainForm.WindowTop = (height-MainForm.WindowHeight)/2
'Dim d5 As Double = (height-MainForm.WindowHeight)/2
'Log(height)
'Log(MainForm.WindowHeight)
'Log(d5)
'Log(MainForm.WindowTop)
showOn(1,MainForm,height1,width1)' form must be shown before this or has no values for left,top etc
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub showOn(Screen As Int, what As Form, height1 As Double, width1 As Double)
Dim maxScreen As Int = desktop.Length-1 ' maximum number of screens
If Screen > maxScreen Then ' if trying to display on non existant screen show on last one
Screen = maxScreen
End If
what.WindowHeight = 800
what.WindowWidth = 1200
what.WindowLeft = what.WindowLeft + desktop(Screen) ' modify form co-ords to go on new screen
what.WindowTop = (height1-what.WindowHeight)/2
Log(what.WindowTop)
Log(height1)
Log(what.WindowHeight)
End Sub
Sub btnFileDialog_Click
fc.Initialize
fc.InitialDirectory = "C:\Users\rfresh1011\Documents\3DGarmin430\"
fc.setExtensionFilter("ForeFlight2", Array As String("*.fpl"))
f = fc.ShowOpen(MainForm)
'Log(f)
Dim x2m As Xml2Map
x2m.Initialize
ParsedData = x2m.Parse(File.ReadString(f, ""))
'Log(m)
'easier to understand the structure with:
'Dim jg As JSONGenerator
'jg.Initialize(m)
'Log(jg.ToPrettyString(4))
Dim flightplan As Map = ParsedData.Get("flight-plan")
Dim waypointtable As Map = flightplan.Get("waypoint-table")
Dim waypoints As List = waypointtable.Get("waypoint")
For Each item As Map In waypoints
Dim identifier As String = item.Get("identifier")
Log(identifier)
'Dim link As String = item.Get("link")
'ListView1.AddSingleLine2(title, link)
Next
End Sub