Is there a way to keep the screen in the same location.

XerVision

Member
Licensed User
I have a windows app version for the PC that connects to my PPC.
I move the app on my pc screen to a different location than the center.
If I select a new screen, the other window is unhidden and shows at the old location. Is there a way to set the location of the app so that the unhidden screens will not show in different places.
 

agraham

Expert
Licensed User
It's undocumented and Erel might have something to say about it but the following works with the usual caveat about making use of undocumented functionality. I guessed that this might work as a Form is a sort of control and all the other controls have Top and Left properties so why not a Form?

There are two Forms, Form1 and Form2. Form1 has Button1, Form2 has Button2. The Form must be built in order for the properties to be present to be set so there is an unavoidable screen jump when Form2 is first displayed but afterwards the forms follow each other nicely around the screen.
B4X:
Sub Globals
Dim Firsttime
End Sub

Sub App_Start
Firsttime = True
Form1.Show
End Sub

Sub Button1_Click
If Firsttime=True then
Form2.Show
Firsttime = False
end if
Form2.Top = Form1.Top
Form2.left = Form1.left
Form2.Show
End Sub

Sub Button2_Click
Form1.Top = Form2.Top
Form1.left = Form2.left
Form1.Show  
End Sub
 
Last edited:

Cableguy

Expert
Licensed User
In the desktop, you can shoose diferent form sizes to your app, so you you size your form to the current screen resolution, it will cover the entire screen...But this maybe is not what you want...still I've noticed that a reduced size form if "maximized" is putted to the 0,0 position on the screen (Top Left)...

Edit : I missed Agraham's post!!
 

Erel

Administrator
Staff member
Licensed User
angraham solution is a good solution and should work properly.
 

XerVision

Member
Licensed User
Still Working on this ...

I have applied the example to my code with some modifications.
I noticed the unavoidable screen jump and am trying to avoid it.

My situation:
I love the PPC size for the PC Screen.
Also I have 18 screens on my app.


So here is a rundown of what I am doing and most of it is working out well. Still having issues with the screen jump.

1.Start App
2. I Initialize all the screens (via a sub-routine) so that I can get the Top and Left Properties and because they initially start in the same location.
3.At the top of each show I make a call to a function which reads in the Previous screen (via a global variable) and New screen. It takes the string names using the Control and sets the New Top/Left to equal the Previous.
And then the new string is set as the Previous.



Step 3 works perfectly. The only problem that I am having is the startup when I have all the screen jumps. I will try setting all the controls on the screen to be not visible and then resetting them later. It's just to a layman the screen jumps may not come off well.


What do you think about my process? It was the most efficient one that I could come up with. But the #1 may not be a good idea? Does it screw up /slow down anything to open all the forms?

Thanks for the starter Agraham and thanks for B4PPC Erel. And thanks for taking the time to look at my post CableGuy.
 

agraham

Expert
Licensed User
The screen jump occurs because when a screen is first shown its Top and Left properties are set to a default and the screen is displayed there before the Top and Left properties are available to be altered.

If your step2 is doing what I suspect, that is looping round the screens before they are shown and setting their Top and Left properties, then this will not work as at this stage the screens do not exist although B4PPC does not throw an error. A screen only exists once it is shown for the first time, only then are the properties available.

Step 3 sounds fine and from what you say apparently works.

I have a couple of thoughts for a workaround that I will post if they work but that will be tomorrow now as food calls!
 

Cableguy

Expert
Licensed User
18 Screens?!
Wow, thats a lot of screens...
are they design created or runtime created screens?

As agraham states, a screen only exists after 1st presentation, so I would suggest this aproach..

on fresh run, shown all forms in reverse order, thsi should only take a few ms....

By doing this you make all forms existing so they can be propertie changed...

Then when showing a form other than main form (form1 by default), re-set the position of the form you want to show....

this eliminates the "jumping" efect, and the first few ms should be almost un-noticeable....
 

XerVision

Member
Licensed User
A little explanation of Number 2

What I meant by initializing all the forms is exactly what Cableguy suggested,
I initialize all the screens by .show for each one. This works except I am getting blips of each screen. I am working on putting all the functionalities in panels and not making visible until later. I will see how this works.

I noticed that the screens with little to no major controls ran through without a trace.
 

agraham

Expert
Licensed User
The only thing I can think of is to do the following.

First make a small app. that can act as a splash screen with an initialisation message that closes itself after a delay

B4X:
Sub Globals
End Sub

Sub App_Start
   Form1.Show ' form has please wait message or similar
   x = timeadd(now,0,0,3)
   do
    doevents ' important! lets the screen finish drawing itself
   loop until now > x
   appclose
End Sub
Now write your main app with its first form a copy of the splash screen app. Then immediately on startup of your main app shell the splashscreen app and then show all your other screens in turn.
B4X:
Sub App_Start
Form1.Show ' must show here or the first show will be in front of splash screen
shell("splash.exe")
' need a slight delay here to let splash screen load
x = timeadd(now,0,0,1)
do
doevents
loop until now > x
' now show all forms, may need a doevents to let them be drawn in turn or may not
End Sub
The splash screen will appear in front of your main app and will hide the screen drawing as AS LONG AS you have shown your first form before shelling, otherwise your first form.show will appear in front of the splash screen. You will need a delay in your main app before you start showing the screens in turn to let the splash screen load and initialize.

There is still a single disturbance on the screen as the main app displays first then the splash screen loads on top off it. Perhaps you could tune the delays and messages so that it looks a deliberate thing. The main screen displays one startup message, waits for the user to read it then shells the splash screen which displays another related message while the main app loads all its' forms.
 

Cableguy

Expert
Licensed User
I've played a while with splash screens, and they are, almost always, very simple to code....
I like agraham's idea, specially if you can came up with some litle animation on your splash screen, like a "loading app" bar.... Just an Idea...

@Agraham, You don't cease to amaze me...I've never would have thought on shelling a startup app to cover the forms initialization...Great work..
 

XerVision

Member
Licensed User
Splash screen Idea is cool.

Thanks, Agraham.

That seems cool to have a splash screen as its own .exe .
Gives me a chance to resize the screen differently as well.


However, after much deliberation, I have chosen to go with a method that may interest others. I placed all the widgets/controls on a panel for each form
I initially have the panels invisible. After all the forms have loaded, I make the panels visible. This seems to fix the problem for the most part. There is a screen blip but it is just the same as any other standard program that I load up. I will try it on the pc's with various processing speeds.
 

XerVision

Member
Licensed User
Something interesting is going on with the Panels

It seems that I can initialize a panel.visible as false and then set it to true in the code. However, the panel doesn't seem to be recognized as Panel.Visible=true until a button is clicked.

Is this a feature or a bug? Maybe I am using it incorrectly.
:sign0137:

:signOops:
My mistake... What happens is this. The .visible value is not known (nor set) until after the Form is Shown.

So I created a routine around the call to get what I needed.

It works.:sign0161:
 
Last edited:
Top