B4J Question Resizing a form to Image size

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

Below is a Sub for selecting and displaying images. [Many thanks to jmon and DonManfred] The Images are screen Snapshots and can be of any size. Theoretically FormLV should be the same size as the window from which the Image was created. The screenshot image attached shows this is not correct.

Any advice on correctly setting the size of the Form?

B4X:
Sub FileSelect
    'Create the modal form:
    FormLV.Initialize("", 300, 500)
    FormLV.SetFormStyle("UTILITY")
  
    Private fc As FileChooser
    fc.Initialize
    fc.Title = $"Saved Files"$
    fc.InitialDirectory = DirPath
  
     Filename1 = fc.ShowOpen(MainForm)
     Filename1 = Filename1.Replace(DirPath, "")
     FormLV.Title = Filename1
   
    If Filename1 <> "" Then
        Private im As Image
        im.initialize(DirPath, Filename1)
        Log(im.Height)
        Log(im.Width)
      
        FormLV.WindowWidth = im.Width
        FormLV.WindowHeight = im.Height
        FormLV.RootPane.Style = "-fx-background-image: url('" & File.GetUri(DirPath, Filename1) & "');"
        FormLV.Show
    End If
End Sub

DemoSize2.png


Regards Roger
 

eurojam

Well-Known Member
Licensed User
Longtime User
Hi Roger,
there are still the borders in your form which are part of the size...you can try to use:
B4X:
FormLV.SetFormStyle( "UNDECORATED")

or you add a value for the borders:
B4X:
FormLV.WindowWidth = im.Width + 10
FormLV.WindowHeight = im.Height + 20

best
stefan
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

A tweak of the code [below] and this problem is solved. I don't really know how.
Now the "FormLVResize = False" is giving me trouble. Tomorrows problem, possibly a new thread.

Regards Roger

B4X:
Sub BtnFiles_action
    If File.Exists(DirPath, "") = False Then File.MakeDir(DirPath, "")
'Find files. Select file to import
    Private Image1 As Image
    Private FileChooser1 As FileChooser
  
    FileChooser1.Initialize
    FileChooser1.Title = $"Saved Files"$
    FileChooser1.InitialDirectory = DirPath
    Filename1 = FileChooser1.ShowOpen(MainForm)
    Filename1 = Filename1.Replace(DirPath, "")
    If Filename1 <> "" Then
        Image1.initialize(DirPath, Filename1)
        FormLV.Initialize("", Image1.Width, Image1.Height)
        FormLV.SetFormStyle("")
        FormLV.Title = Filename1
        FormLV.RootPane.Style = "-fx-background-image: url('" & File.GetUri(DirPath, Filename1) & "');"
        FormLV.Show
        Timer2.Initialize("Timer2",1000)  'Timer2_Tick  FormLVResize = False
        Timer2.Enabled = True
    End If
End Sub

Sub Timer2_Tick
   FormLV.Resizable = False
   Timer2.Enabled = False
End Sub
 
Upvote 0
Top