can i set a fix position for the app window when i debug?
it covers my code because it is always centered and when i move it to another position on the screen i would like to have it load again at that position and not centered again.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
#if debug
Dim f As Form = B4XPages.GetNativeParent(Me)
f.WindowLeft = 10
f.WindowTop = 10
#end if
ImageView1.SetImage( xui.LoadBitmap(File.DirAssets, "nevergiveup.jpg") )
End Sub
Private kvs As KeyValueStore
....
Private Sub B4XPage_Background
#if B4J
B4XPages.MainPage.SavePagePosition(Me)
#end if
...
Sub B4XPage_Appear
B4XPages.MainPage.LoadPagePosition(Me)
...
Public Sub SavePagePosition (Page As Object)
#if B4J
Dim f As Form = B4XPages.GetNativeParent(Page)
If f = Null Or f.IsInitialized = False Then Return
kvs.Put(B4XPages.GetPageId(Page), FormToPP(f))
#end if
End Sub
Public Sub LoadPagePosition (Page As Object)
#if B4J
Dim f As Form = B4XPages.GetNativeParent(Page)
Dim pp As PagePosition = kvs.Get(B4XPages.GetPageId(Page))
If pp = Null Then Return
SetFormFromMap(pp, f)
#end if
End Sub
There is no default code in the project template that centers the form, yet that is the case. I assume there is code in the core that centers the form on the screen.
thanks all for you advises. i don't use b4xpages because i need just a tool to help me build my mobile app so i use this code and it works fine:
B4X:
Private Sub MainForm_CloseRequest (EventData As Event)
File.WriteMap(File.DirApp,"pos.txt",CreateMap("left":MainForm.WindowLeft,"top":MainForm.WindowTop))
End Sub
Private Sub setPosition
If File.Exists(File.DirApp,"pos.txt") Then
Dim m As Map = File.ReadMap(File.DirApp,"pos.txt")
If m.ContainsKey("left") Then MainForm.WindowLeft = m.Get("left")
If m.ContainsKey("top") Then MainForm.WindowTop = m.Get("top")
End If
End Sub
i call setPosition in AppStart() before MainForm.Show