x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Scaling eVB window to fit resolution

I dunk for bananas Page Icon Posted 2024-01-27 11:21 AM
#
Avatar image of I dunk for bananas
H/PC Elite

Posts:
707
Location:
Europe
Status:
Is it possible to scale my programs window to fit the resolution of the device it's being run on? Ideally I'd like to not have to manually move the positions of all of the elements, so would it be possible to "stretch" everything and keep their relative positions?

edit: excuse the typo in the title
 Top of the page
C:Amie Page Icon Posted 2024-01-27 12:06 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
18,012
Location:
United Kingdom
Status:
Typo fixed.

Yes, but either you have to scale the form controls width/height or scale the gaps around them. With some screens being 4:3, some 2.66:1 and others 2:1, it could wind up looking very strange if you scale the controls. You basically have to create your own grid layout, convert all positioning to relative percentages accordingly. All of which starts with a calculation for the screen width and height to dynamically scale the form area (and obviously the Int() function to prevent passing decimal positional numbers).

A slightly saner approach - but still complex one - might be to partition the form canvas into panels and then relatively position the panels using percentage positioning, then positioning form controls as offsets to the relative position of the top left of the panel. Of course VB doesn't support that either, so you would have to write the code behind logic for it as a custom control and assemble all form object positions in the code at runtime rather than using the form designer. You might also need to force it to double buffer otherwise you might find the UI flashes when it draws too.

TLDR: Use VB .net instead. It supports layout control positioning such as FlowLayout, GridLayout and DockedPanels rather than absolute positioning.
 Top of the page
I dunk for bananas Page Icon Posted 2024-01-27 12:09 PM
#
Avatar image of I dunk for bananas
H/PC Elite

Posts:
707
Location:
Europe
Status:
Thank you, I understand. That's a little annoying
The way my program currently works is as a fixed size window in the center of the screen. I was hoping I could take advantage of devices with taller screens and stretch the window downwards if the vertical resolution is above a certain threshold (this would all happen when the window spawns, and it wouldn't be resizable by the user)

Edited by I dunk for bananas 2024-01-27 12:10 PM
 Top of the page
C:Amie Page Icon Posted 2024-01-27 12:12 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
18,012
Location:
United Kingdom
Status:
You can certainly stretch the window, that is no problem, just set it to the screen width/height and then add a substitution for whether the taskbar is visible. However this will leave all the form designer controls in the top left and a sea of blank space unless you get creative with relative positioning.
 Top of the page
I dunk for bananas Page Icon Posted 2024-01-27 12:14 PM
#
Avatar image of I dunk for bananas
H/PC Elite

Posts:
707
Location:
Europe
Status:
I think what I might do is just check if the window is above a certain threshold and then programmatically resize my elements to take advantage of the extra space (by just supplying new fixed coordinates).
Do you know if I can do that before the form ever shows up? I'd like to avoid weird jumping and flashing at startup
 Top of the page
C:Amie Page Icon Posted 2024-01-27 1:08 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
18,012
Location:
United Kingdom
Status:
WinCEDev probably has better knowledge than me here - it has been decades since I used it properly. If you use the form designer and then reposition them in the code behind, there is chance that it will flash if the repositions are handled after form load. I believe that the load() event itself however is automatically double buffered and occurs before the form first draws, so as long as you either use the form designer and reposition in here, or add controls in the code behind before this completes, it should be fine.
 Top of the page
WinCEDev Page Icon Posted 2024-01-27 5:22 PM
#
Avatar image of WinCEDev
Factorite (Senior)

Posts:
77
Location:
Europe
Status:
For the most part you can do it the same way as in VB6. If you want to resize the window based on the screen resolution, you can use the Screen object's Width and Height properties to get the device's resolution:
MsgBox "Device screen width: " & Screen.Width & vbNewLine & "Device screen height: " & Screen.Height

You can use Form_Load and/or Form_Resize to set up your window layout, Form_Load happens before the window is shown so it shouldn't cause any flickering. Form_Resize happens any time your window size changes, and surprisingly it works perfectly in eVB despite the inability to set up a user-resizable window without doing API calls.

Would you be willing to share a screenshot of the app window you're working on? I may be able to give you some more specific advice.

One thing of note is that like VB6, eVB by default uses twips instead of pixels for its coordinate system. It ensures that form elements stay the same size on high DPI displays, though I'm not sure if that's a thing with Windows CE. You can change it to pixels if you want, but I generally don't recommend it as the whole language pretty much assumes you're using twips and it feels like going against the stream when using anything else.
 Top of the page
Jump to forum:
Seconds to generate: 0.140 - Cached queries : 63 - Executed queries : 10