B4J Question Fix Postion when debuging

ilan

Expert
Licensed User
Longtime User
hi

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.

thanks
 

emexes

Expert
Licensed User
Maybe this? It works here.

B4X:
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
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
fix position for the app window
Search for "KeyValueStore" for windows positions.
B4X:
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
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
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

thanks guys 🤟
 
Upvote 0
Top