Fill background with colour or multiple colours if display size > form size

yankarinRG

New member
Local time
Today, 08:52
Joined
Nov 6, 2016
Messages
5
Hello, is there a fast and cheap way to fill the background of a form with a single or more colours when the size of the form is smaller than the one of the screen?
I am developing a 1024x768 sized database and I would like to make it as good looking as possible. I would like to center the forms to the screen (i.e. on a 1920x1080 display the form will have 448 px as left and right padding and 156 ad top and bottom) and, if displayx >1024 and displayy > 768 then add a colour filler.
Is it possible?
I set the forms to popup and, on load, doCmd.Maximize and, even with auto center and auto dimension set to ON, it doesn't behave as I want. Thanks :)
 
You could add your form to a container form - so your main form is a subform.

Then center the subform when the container resizes.

Code:
Private Sub Form_Open(Cancel As Integer)
    Detail.BackColor = vbRed
End Sub

Private Sub Form_Resize()
    If MySubForm.Width > Me.InsideWidth Then
        MySubForm.Left = 0
    Else
        MySubForm.Left = (Me.InsideWidth / 2) - (MySubForm.Width / 2)
    End If

    If MySubForm.Height > Me.InsideHeight Then
        MySubForm.Top = 0
    Else
        MySubForm.Top = (Me.InsideHeight / 2) - (MySubForm.Height / 2)
    End If
    
End Sub
 
Hello static thanks for helping me!
Since I am going to use the database in full screen, is this code the same?
Code:
    Private Sub Form_Load()
    DoCmd.Maximize
    Me.subForm.Left = (15 * getDisplayResolution(0) - Me.subForm.Width) / 2 'x padding
    Me.subForm.Top = (15 * getDisplayResolution(1) - Me.subForm.Height) / 2 'y padding
End Sub

In a module:
Code:
Public Declare PtrSafe Function getDisplayResolution Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Thanks! Feel free to suggest ways to improve the code!
 
Last edited:
Looks similar.
I try to avoid using API calls and I can't see what you're gaining by using one here. By maximising the form you know how big the screen is.

Onload is a onetime event. Resize fires every time the screen size changes.
Unless this is the only application your users are going to be using I'd think very carefully before forcing users into full screen, especially when a good portion of the screen is blank. I would probably find it very annoying and badly designed.
 
Thanks for the feedback. As I really like the style I am using, I will provide a sample so everyone can understand what I am doing/want to do (and get some feedback!):
i.imgur.com/xIxSnIA.jpg
-The red frame is a safe area: It is 1024 by 768 and it will never get rezised (implies user resolution is at least 1024 x 768)
-The blue lines describe the center of the user display: the subForm will always be centered there
-The outside area is a fill: if the user resolution is bigger then they'll have their background filled else it'll get cropped

Hope you like it!
 

Users who are viewing this thread

Back
Top Bottom