[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Code for Resizing forms to desktop resolution.

Posted on 2006-05-25
27
Medium Priority
?
459 Views
Last Modified: 2012-06-21
How do I resize multiple forms when opened in a db?
I do have code that will resize forms to a specific resolution if manually tweaked but I am trying to explore other possibilities.

But what I am hoping to achieve is that when a form is opened it should automatically resize the form to the Windows resolution which my be:
form 800 x 600 up to 1280 x 1024.

In any case, if a user set's his desktop resolution to 1024 x 768 for example, then the code in the db should adjust the form being opened to the desktop resolution.

Any help will be appreciated.
0
Comment
Question by:billcute
  • 14
  • 13
27 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16760409
If u resize forms, the form design may not look nice

u should define your form to the lowsest resolution of your users

http://www.mvps.org/access/forms/frm0042.htm

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16760419
link on
Automatically resize forms to current screen resolution

 http://www.mvps.org/access/general/gen0002.htm
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16760448
there is a form resizer here also
http://jamiessoftware.tk/


Note, I have not tried these code snippets, I just know they exist

I tend to design my screens knowing what the min screen resolution is
Luckily for me, its all 1024 x 768

800x600 is a bit rare now. I cannot remember last time I saw someone using that resolution

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:billcute
ID: 16760452
I have checked out the referred site...but dont think it addressed my concern.

The resizing code will always be to maximize the main forms to the desktop resolution. The referred  site did not elaborate on different resolution.

If you wish I can post a link (later on this evening) to my own source code which can be modified further for different Window resolution.

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 16760466
sorry...we missed each other during cross posting..I will checkout these other ones and let you know later

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 16760494
This referred site is my current code;
http://jamiessoftware.tk/

the code requires manually changes to function to Windows rsolution. I will check the other later on.
0
 
LVL 4

Author Comment

by:billcute
ID: 16760512
The other is peter's software, one has to buy it. Is it possible to amend this one further if licensing allows it?

http://jamiessoftware.tk/

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 16766141
rockiroads,
I have checked out these links. hat would you recommend in light of my comments above.

Regards
Bill
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16766488
Bill, Ive not tried any one of them. I just supplied you some links which I felt may help you.
I will try one out now and let you know
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16778772
**A)

Bill, I take it you have tried the Access form resizer from jamiesoftware?

It gives u the code, u can export to your own DB, then just call the method ReSizeForm, passing in form object
e.g.

private sub Form_Load()

    ReSizeForm Me

end sub

this resizes forms and controls



**B)
Peter's software is an MDE, you cannot export that code so Im not aware of its use.



**C)
If you want to get the current screen resolution, here is some code that u can use

Add this code into a module


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

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1

Sub GetScreenSize()

    Dim x As Long, Y As Long, sYourMessage, iConfirm As Integer
    x = GetSystemMetrics(SM_CXSCREEN)
    Y = GetSystemMetrics(SM_CYSCREEN)
 
    MsgBox "Current screen size is " & x & " x " & Y & vbCrLf
   
End Sub


Now if u run the procedure getscreensize, it comes up with a msgbox

0
 
LVL 4

Author Comment

by:billcute
ID: 16779957
rockiroads,
How or where should I call your above suggested Sub

Regards
Bill
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16780067
alright bill,

is it the get screen resolution u want?

simply place anywhere, probably better in a module

it will return 1024 x 768 or whatever resolution it is

i.e.
x = 1024 or 800
y = 768  or 600

I guess u can then return these values to the caller
e.g

public Sub GetScreenSize(byref x as long, byref y as long)

    Dim iConfirm As Integer

    x = GetSystemMetrics(SM_CXSCREEN)
    y = GetSystemMetrics(SM_CYSCREEN)
 
End Sub

you then call it in your form code or wherever like this

dim x as long
dim y as long

GetScreenSize x,y



that is one method, the other method is to pass the form in, thats if the code you are calling requires the form
e.g.

public Sub GetScreenSize(frm As Form)

    Dim x As Long, Y As Long, sYourMessage, iConfirm As Integer
    x = GetSystemMetrics(SM_CXSCREEN)
    Y = GetSystemMetrics(SM_CYSCREEN)

    'Now call your code  
    'CALL YOUR resize code here passing in frm as the form and x and y if thats what it takes
   
End Sub


u then call this example from form simply by

GetScreenSize Me



I dont know the code you are calling to resize forms, what type of parameters does it take?


0
 
LVL 4

Author Comment

by:billcute
ID: 16780180
I think I will stick to http://jamiessoftware.tk/ example.

The section in the module for manipulating the resolution is at:
Private Const DESIGN_HORZRES As Long = 800 '    640   '<- CHANGE THIS VALUE TO THE RESOLUTION
                                                'YOU DESIGNED YOUR FORMS IN.
                                                '(e.g. 800 X 600 -> 800)
Private Const DESIGN_VERTRES As Long = 600   '480   '<- CHANGE THIS VALUE TO THE RESOLUTION
                                                'YOU DESIGNED YOUR FORMS IN.
                                                '(e.g. 800 X 600 -> 600)
Private Const DESIGN_PIXELS As Long = 96        '<- CHANGE THIS VALUE TO THE DPI
' ************

'  Call is on the Form's On Load:
ReSizeForm Me

Note: Form designed at 800 x 600 resolution

Regards
Bill
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16780216
ok, hang on
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16780237
there is this current code, look for it, we are going to change this one

this code uses the constants, it now going to be tweaked


Private Function getFactor(blnVert As Boolean) As Single

Dim sngFactorP As Single

On Error Resume Next

    If getScreenResolution.DPI <> 0 Then
        sngFactorP = DESIGN_PIXELS / getScreenResolution.DPI
    Else
        sngFactorP = 1 'Error with dpi reported so assume 96 dpi.
    End If
    If blnVert Then 'return vertical resolution.
        getFactor = (getScreenResolution.Height / DESIGN_VERTRES) * sngFactorP
        MsgBox "h=" & getFactor
    Else 'return horizontal resolution.
        getFactor = (getScreenResolution.Width / DESIGN_HORZRES) * sngFactorP
        MsgBox "w=" & getFactor
    End If
   
End Function
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 16780276
look for this comment


'--------------------------------- END API DECLARATIONS----------------------------------


before this line, add the following code

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

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1





Now back to that function getFactor, here it is rewritten


Private Function getFactor(blnVert As Boolean) As Single

    Dim sngFactorP As Single
    Dim lWidth As Long, lHeight As Long, sYourMessage
   
    On Error Resume Next

    If getScreenResolution.DPI <> 0 Then
        sngFactorP = DESIGN_PIXELS / getScreenResolution.DPI
    Else
        sngFactorP = 1 'Error with dpi reported so assume 96 dpi.
    End If
   
    'Get current screen resolution
    lWidth = GetSystemMetrics(SM_CXSCREEN)
    lHeight = GetSystemMetrics(SM_CYSCREEN)

    'BILL, THIS MSGBOX IS A DIAGNOSTIC, TELLS U THE SCREEN RES
    'USED TO TEST/CONFIRM IT WORKS, THEN DELETE AFTERWARDS
    MsgBox "Width=" & lWidth & vbCrLf & "Height=" & lHeight

    'Now use lWidth, lHeight instead of the previously defined constants
    If blnVert Then 'return vertical resolution.
        getFactor = (getScreenResolution.Height / lHeight) * sngFactorP
    Else 'return horizontal resolution.
        getFactor = (getScreenResolution.Width / lWidth) * sngFactorP
    End If
   
End Function


0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16780289
Hope this makes sense
good luck


I tried by hardcoding the values lWidth and lHeight
0
 
LVL 4

Author Comment

by:billcute
ID: 16780408
rockiroads,
After the amendments were pasted there were no errors and the fiunctions worked as was designed for 800 x 600.

When I changed the desktop screen resolution to 1024 x 768, the code's msgbox reported the same resolution except that the form was expected to stretch (maximize) to full screen resolution. The form was sma and condensed rather than stretching to the screen resolution.


It was suggested in the Readme files of the download that the best way is to design with the lowest resolution, in my case the lowest resolution I chose to design was 800 x 600 since most pc monitors nowadays are from 800 x 600 and up to 1280 x 1024 for newer LCD or plasma flat screen monitors.

Currently the resolution I configured the ReSizeForm Me function - my idea is if there is a way to include the following resolution that would be detected by the form upon loading of the appropriate form.

800 x 600; 1024 x 768 and 1280 x 1024 respectively.

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 16780417
.....correction for 2nd paraagraph of my last comment>

The form was small and condensed rather than stretching (maximizing) to the screen resolution.      ^^^
0
 
LVL 4

Author Comment

by:billcute
ID: 16780610
I also conducted other test such as changing the resolution manually to 1024 x 768 and 1280 x 1024 respectively.

I noticed that maximum expandability of the module is 1024 x 768. any resolution that is higher that than is defaulted to 1024 x 768.

In that case, if the form can at least maximize up to the 1024 x 768 with your amendment, it would be great.

Regards
Bill
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16784294
Bill, have u tried JamieSoftware code without my changes and changing the constant values?
what results do you get?

I have not changed anything in his code except to specify the current user's screen resolution.

0
 
LVL 4

Author Comment

by:billcute
ID: 16784685
rockiroads,
I have just tested JamieSoftware code without your changes and found that the code has limitation - it doesn't work with a resolution greater than 800 x 600.

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 16815023
rockiroads,
Any other idea or thoughts on this matter?

Regards
Bill
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16818128
I dont know to tell u the truth
I also dont know what kind of results you are after
What I suggest is u try out others till u find one u like
then we can try work that to your needs
0
 
LVL 4

Author Comment

by:billcute
ID: 16820634
ok
0
 
LVL 4

Author Comment

by:billcute
ID: 16850427
rockiroads,
I have decided to award you for this post....due to the limitation of the sample code itself. I can always re-open this post in the future if needed.

Thanks for your assistance.

Regards
Bill
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16858976
ok, thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question