Windows position

WZSun

Member
Licensed User
Hi,
When user launched a Basic4PPC-compiled as Windows app, the application will starts in the center of the desktop screen. When user moves the app to a different location, subsequent forms will move back to the center. However, subsequently when the same form is being accessed, the position where the form was previously is used.

A request here.. when the app is moved to a different location, it would be great to have all forms shown on the same location in the first instance, rather than in the center.
 

klaus

Expert
Licensed User
If you want that at the next start of the desktop program the Main form is placed at the position where it was the last time, you can save it's coordinates in a file and read it at start-up and position the Main form. And then the others with Erel's code.

Best regards
 
Last edited:

WZSun

Member
Licensed User
Hi All,
Thanks... I think saving to a file or registry is better as users can move the app from 'any form'.. and need not be in Form1... as it's all transparent to them.. this way, regardless of which Form they're in.. it will be displayed in the 'last moved position'.

Thanks to all!!!
 

WZSun

Member
Licensed User
Hi Erel,
I tried using the methods suggested. It works.. but noticed there was 'flashing' of the windows from center to the position moved. This is obvious when the Form is displayed the first time. Subsequently it will not.

In your example..

Sub Button1_Click
form2.Show
form2.Left = form1.Left
form2.Top = form1.Top
End Sub

Form2 was shown before the 'moving' was done. If I changed it to:

Sub Button1_Click
form2.Left = form1.Left
form2.Top = form1.Top
form2.Show
End Sub

the Form2 will not moved to the new coordinate the first time Form2 was shown, however it will recognise the coordinate on subsequent display of Form2.

Is there a way to prevent the 'windows flashing' from being seen?
 

Erel

Administrator
Staff member
Licensed User
This code will prevent the flashing (door is a Door object):
B4X:
Sub App_Start
    Form1.Show
    door.New1(false)
    door.FromControl("form2")
    door.SetProperty("StartPosition","Manual")
'    door.FromControl("form3")
'    door.SetProperty("StartPosition","Manual")
'    ...
End Sub


Sub Button1_Click
    form2.left = form1.left
    form2.top = form1.top
    form2.Show
End Sub
 

klaus

Expert
Licensed User
Hi Erel and WZSun,
Works fine !
I modified the code a bit to postion also the first form, in some programs I have only one form.

B4X:
Sub App_Start
    LoadInit             ' reads the position of the main form frmTop and frmLeft

    door.New1(false)

    If Not(CPPC) Then
      door.FromControl("form1")
      door.SetProperty("StartPosition","Manual")
    End If

    Form1.Top=frmTop  ' sets the position
    Form1.Left=frmLeft
    Form1.Show

    If Not(CPPC) Then
      door.FromControl("form2")
      door.SetProperty("StartPosition","Manual")
'      door.FromControl("form3")
'      door.SetProperty("StartPosition","Manual")
    End If
'    ...
End Sub
Best regards
 
Last edited:

klaus

Expert
Licensed User
The code in my previous post has been modified.

It must be
B4X:
  If Not(CPPC) Then
    door.FromControl("form1")
    door.SetProperty("StartPosition","Manual")
  End If
Otherwise there will be a Null Exception error on the divice.

Best regards
 

WZSun

Member
Licensed User
Hi,
Perhaps it's due to my limited skillset.. I could not get the form to position where it's moved at.

Let's say I have 3 forms. Each form has a button to click to go to the next form.

When app starts, form1 is shown. I then move form1 to another area. Then I click on Form1_Button1 which shows Form2. Form2 should be in new position. Now, I move Form2 to another new location. Then click on Form2_Button to show Form3 which should be displayed in the new location.

I tried but it doesn't. Can you create a sample sbp demo so that I can grasp correctly? I believe the demo would also be useful for beginners.

Thanks in advance!
 

WZSun

Member
Licensed User
Hi All,
I have managed to identfiy the cause.. someone I stated the frmTop/frmLeft before the form.show... which is why the form doesn't appear as it should be, after moving.

In short.. I have resolved the issues..



Hi Erel,
Just one question.. when an application (compiled for Windows) is closed (exit).. there is a flashing window.. is there a way to 'hide' this?
 

WZSun

Member
Licensed User
Hi cableguy,
THANKS for the tip.. initially I thought it works.

But upon closer look noticed the flashing windows is from 'Compact Framework'.. which may be beyond our control. anyway, just a minor irritation...

Rgds
 
Last edited:
Top