• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Visual Basic Form Background Picture Sizing/Positioning

Is it possible to automatically set the system display settings or at least ignore the settings when a visual basic form loads?

In other words, we have visual basic forms that look differently, depending on which computer they are loaded onto.  We are trying to find a way to allow all users to see the forms in exactly the same way, without forcing everyone to change their computer display settings.
0
dekkyb
Asked:
dekkyb
  • 3
  • 2
  • 2
  • +4
1 Solution
 
Erick37Commented:
Do you mean System Colors, Fonts, and Resolution?
0
 
CrinCommented:
Hello dekkyb,

Most accurate way is to use 16 colors, and to check forms design at 640x480, or 800x600 at least...

Also read help about Scale, ScaleTop, ScaleLeft, ScaleWidth, ScaleHeight...

WBR

Crin
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
CrinCommented:
Hello dekkyb,

Most accurate way is to use 16 colors, and to check forms design at 640x480, or 800x600 at least...

Also read help about Scale, ScaleTop, ScaleLeft, ScaleWidth, ScaleHeight...

WBR

Crin
0
 
tmackCommented:
You have the choice to use either colors from the palette or the system. I usually use from the palette as I cn control the way the app looks at all times. Just make these changes to all your controls background, forground ect properties in the application.


T
0
 
dekkybAuthor Commented:
Part of the issue is that we can't determine which settings are causing the problem.  On one system the form will look correct.  On another system, the form background image will be smaller than the form frame, causing a strip of gray to appear along one side.  Manually changing the screen resolution, font sizes, and/or color depth (24-bit, 32-bit, etc.) does not seem to correct the problem.
0
 
dekkybAuthor Commented:
Part of the issue is that we can't determine which settings are causing the problem.  On one system the form will look correct.  On another system, the form background image will be smaller than the form frame, causing a strip of gray to appear along one side.  Manually changing the screen resolution, font sizes, and/or color depth (24-bit, 32-bit, etc.) does not seem to correct the problem.
0
 
AzraSoundCommented:
if you port your program to another system with the identical settings you have on your computer that you created it on it still causes problems?
0
 
CrinCommented:
Hmmm...

seems it depends on system setting of the borders width.

Try to play local with border appearance and if the trouble here - set BorderStyle to Fixed Single...

Otherwise - please send more detailed information.

Sincerely yours,

Crin


0
 
Erick37Commented:
You can set the window's size to match the picture size at runtime with the AdjustWindowRect API.
Simple Example:

Option Explicit
Const WS_OVERLAPPED = &H0&
Const WS_CAPTION = &HC00000
Const WS_SYSMENU = &H80000
Const WS_THICKFRAME = &H40000
Const WS_DLGFRAME = &H400000
Const WS_MAXIMIZEBOX = &H10000
Const WS_MINIMIZEBOX = &H20000
Const WS_BORDER = &H800000
Const WS_POPUP = &H80000000
Const WS_FIXEDSINGLE = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_DLGFRAME)
Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function AdjustWindowRect Lib "user32" _
    (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Long) As Long

Private Sub Form_Load()
    Dim cx As Long, cy As Long
    Dim rc As RECT
    Dim bHasMenu As Boolean 'set true if window has a menu
    bHasMenu = False
    'get picture size in pixels
    cx = ScaleX(Me.Picture.Width, vbHimetric, vbPixels)
    cy = ScaleY(Me.Picture.Height, vbHimetric, vbPixels)
    rc.Right = cx
    rc.Bottom = cy
    'For Style 2 - Sizable
    'Call AdjustWindowRect(rc, WS_OVERLAPPEDWINDOW, bHasMenu)
    'For Style 1 - Fixed Single
    Call AdjustWindowRect(rc, WS_FIXEDSINGLE, bHasMenu)
    cx = ScaleX(rc.Right - rc.Left, vbPixels, vbTwips)
    cy = ScaleX(rc.Bottom - rc.Top, vbPixels, vbTwips)
    Me.Width = cx
    Me.Height = cy
    Debug.Print Me.Width; Me.Height
End Sub
0
 
Olli083097Commented:
dekkyb:
It could be that the properties for the screen are different. Try to use Windows-Standard on both computers. If this solves the problem you could try the GetSystemMetrics API. This API will measure the width and the height of the borders. You can use this in the Resize event.

Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

'constants for GetSystemMetrics API
Public Const SM_CXFRAME = 32
Public Const SM_CYFRAME = 33

Look on the MSDN Library for more info.
0
 
g_jones021500Commented:
why not have the image stretch to fit the form when the form loads?
Is this a MDIChild form?
Does the form automatically handle control resizing on form resize?
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now