I'm making a program that uses several forms, some are maximized some are not. My problem is when I try to run my program on other pc's that are using resolutions lower than 1280x800 the form now is to big for the monitor.

Is there a way that the forms that are maximized will re size according to the resolution of the pc? So the form will looks the same in any resolution. Thanks.

If you mean just the size of the form border, then it will resize automatically IF you set the WindowState = 2-Maximized.

You can also set the form size to be exactly as screen size by:

Form1.Height = Screen.Height
Form1.Width = Screen.Width

The Screen object gives you the current resolution of the monitor so you can act upon it.

U want to resize controls automatically when form resizes.

Have a look at this sample project i have attached here. Observe the tag Property of each control.

Changing the tag property helps in resizing/positioning as per ur requirement.

u can use varWidth, varVertical, fixBottom, fixRight etc.

this code can be found at the following url with some additional information

http://www.codeguru.com/vb/gen/vb_forms/resizing/article.php/c5949/

Regards
Shaik Akthar

Thanks guys but that's not exactly what I meant. I want my program to change resolution when run in a pc that's using different resolution when the program was created. For example run a maximized form in for pc, then closed it and lower your resolution let say 800X900. then run again the maximize form. See the difference? That's the problem I want to solve.

have u using any picture in your form. and need to change it with resolution. what u want to mean ? i think Shaik Akthar's sample is your solution. if u need to change your picture then try it.

Image1.Width = Me.Width

Image1.Height = Me.Height - 300
or send your project.

I think (actually hope) I've got what you mean.
You want your program to change the screen resolution into a specific resolution that is most suitable for your program.
So that you can be sure the program is displayed optimally in spite of what the user's resolution was.
Is that what you need? If so; I'll post the code.

I think (actually hope) I've got what you mean.
You want your program to change the screen resolution into a specific resolution that is most suitable for your program.
So that you can be sure the program is displayed optimally in spite of what the user's resolution was.
Is that what you need? If so; I'll post the code.

Hi Drycola,

Would really appreciate it if you could send this code to me (fairdes@gmail.com) as I am having the same troubles.

Thanks,
Fady

Hello Fady,

You may put the following code in a module:

Option Explicit
Const WM_DISPLAYCHANGE = &H7E
Const HWND_BROADCAST = &HFFFF&
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_UPDATEREGISTRY = &H1
Const CDS_TEST = &H4
Const DISP_CHANGE_SUCCESSFUL = 0
Const DISP_CHANGE_RESTART = 1
Const BITSPIXEL = 12
Private Type DEVMODE
    dmDeviceName As String * 32
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * 32
    dmUnusedPadding As Integer
    dmBitsPerPel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type
Private Declare Function EnumDisplaySettings Lib "User32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "User32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Private Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function CreateDC Lib "Gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
Private Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Dim OldX As Long, OldY As Long, nDC As Long, OldColors As Long
Dim DevM As DEVMODE, ScInfo As Long, erg As Long

Private Function ChangeRes(X As Long, Y As Long, Bits As Long, ColorDepth As Long) As Boolean
erg = EnumDisplaySettings(0&, 0&, DevM)
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = X
DevM.dmPelsHeight = Y
DevM.dmBitsPerPel = ColorDepth
erg = ChangeDisplaySettings(DevM, CDS_TEST)

Select Case erg&
    Case DISP_CHANGE_SUCCESSFUL
        erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
        ScInfo = Y * 2 ^ 16 + X
        SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
        ChangeRes = True
    Case Else
        ChangeRes = False
End Select
End Function

Public Function Change_Resolution(Width As Long, Height As Long, ColorDepth As Long) As Boolean
erg = EnumDisplaySettings(0&, -1&, DevM)
OldColors = DevM.dmBitsPerPel
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
Change_Resolution = ChangeRes(Width, Height, GetDeviceCaps(nDC, BITSPIXEL), ColorDepth)
End Function

Public Function Restore_Resolution()
ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL), OldColors
DeleteDC nDC
End Function

Don't worry if you see it a little complicated.
All you have to know is the following commands:

Change_Resolution (Width As Long, Height As Long, ColorDepth As Long) As Boolean
'Call this function on Form_Load to change the resolution. If it returns TRUE then the function is successful.

Restore_Resolution ()
'Call this function on Form_Unload to restore original resolution when the program close.

Greets from your IRAQi new friend!

Hello Fady,

Change_Resolution (Width As Long, Height As Long, ColorDepth As Long) As Boolean
'Call this function on Form_Load to change the resolution. If it returns TRUE then the function is successful.

Restore_Resolution ()
'Call this function on Form_Unload to restore original resolution when the program close.

Greets from your IRAQi new friend!

Hi Drycola,

Thanks very much for the code. Sorry if this sounds stupid, but how do I call both functions in a form.

Thanks again.
Fady

Yes Drycola that's exactly what I meant. But Nothings change when I run the program.
How can I call functions? It is just like calling public subs?

Also do I need to change something in your code to suit mine?

Hello Fady,
Your question is not stupid at all.

Hello iamnoangel26,
Here is how to use the functions, I don't think you need to change anything.

Here is the answer for you both:

Let's say you want to change the resolution to 800x600 32bit when your program start; you should call the function from the Form_Load sub, it will look like this:

Private Sub Form_Load ()
Change_Resolution 800, 600, 32
End Sub

and when your program terminates (in other words: Form_Unload) you should call the Restore_Resolution function:

Private Sub Form_Unload (Cancel as Integer)
Restore_Resolution
End Sub

Any additional questions are WELCOME! :)

Thanks Drycola. Works brilliantly! Not wanting to push my luck any further, I don't suppose you would be able to help with a similar problem. Rather than changing the resolution, how can you resize a form and its controls based on whatever resolution the user has. Thanks again for your help.

Hello Fady,

Its nice to hear that it works.
I didn't understand what you said about your luck, but I'd like to tell you that I'm always ready for help, just tell me and I'll try to do my best!
What you need about resizing form is already found on this forum, you can check it on :
http://www.daniweb.com/forums/thread143320.html

Note: If the 'Resolution Problem' has been solved; then please mark this thread as solved so as to increase my reputation ;)

Greets

Thanks again Drycola. About 'pushing my luck', it's a phrase we use when you are doing something that might be a little bit annoying to somebody else. In my case I thought my asking for all your help might get a little bit annoying for you. Not sure how you mark the thread as solved though.

Hello Fady,
I'm really glad to help anyone who needs help and that's why I'm here ;)
I think the thread poster is the only one who is capable of marking the thread SOLVED, you may simply click on 'Add to Drycola's Reputation' hehehe.

This article has been dead for over six months. Start a new discussion instead.