Check Monitor Width (Screen Width

ajetrumpet

Banned
Local time
Today, 00:24
Joined
Jun 22, 2007
Messages
5,638
Folks,

Does anyone know how to check the monitor width of the computer? I am not looking for the screen resolution, but rather the width of the computer monitor.

I have a problem with a form that I made....I have many images and boxes on a form, and the form is only as wide as the IBM I produced it on. all images are centered on the form manually. The problem comes where I try to open the form on my HP laptop, where i have a 15 in screen. I get a form with extra grey background space on the right side of the screen because the form is open MAXIMIZED. Is there anyway I can get around this?

I am looking for a way to center all of the images on the form, regardless of what monitor width I am working with. thanks!
 
thank boyd, but it doesn't work for me. it only centers forms that are not already maximized.

by the way, setting the AutoCenter property to "YES" for any form will do the same thing that your code does...
 
thank boyd, but it doesn't work for me. it only centers forms that are not already maximized.
I shoudl have explained why I thought the code woudl be helpful. The code has to figure out the screen size to be able to position the the form. This is the part that may be helpful.


by the way, setting the AutoCenter property to "YES" for any form will do the same thing that your code does...
Actually that is not true. The code in my example can change the position (center) of an already opened form.

Setting the AutoCenter property to "YES" only works when the form is first opened. It does not work for a form that is already opened.

Setting the AutoCenter property to "YES" is great for when the form is first opened. You need the code in my example after the form has been opened is you need to center the form again. Depending on what you are trying to do, you may need to use them together to keep a form centered.
 
experience over youth. i stand corrected boyd. i will try your code out again and get back to you on weather or not i can use the screen size to my advantage. thanks man.
 
Adam,

No problem. I should have explained that in my original reply.
 
boyd,

i have been playing around with this, and I came up with:
Code:
    Call apiGetWindowRect(pfrmForm.hwnd, rctForm) ' Get the form window coordinates
    
    Debug.Print pfrmForm.hwnd
    Debug.Print rctForm.Bottom
    Debug.Print rctForm.Top
    Debug.Print rctForm.Left
    Debug.Print rctForm.Right
this gives me these numbers:

590954
784
22
-4
1284

can you tell me how to read this? is this in pixels? twips? and what is hwnd? that number changes everytime i print these values on the form when it is maximized. i'm a little uncertain how i can use these numbers, but i think i can if i get a push in the right direction.
 
have you tried

Code:
Private Sub Form_Open(Cancel As Integer)
docmd.runcommand accmdsizetofitform
End Sub
 
can you tell me how to read this? is this in pixels? twips? and what is hwnd? that number changes everytime i print these values on the form when it is maximized. i'm a little uncertain how i can use these numbers, but i think i can if i get a push in the right direction.

you could check here but I would imagine you will go around in circles trying to get a straight answer. http://msdn.microsoft.com/en-us/library/ms633519(VS.85).aspx

Why not compare these results with the access ones.

hwnd is the windows handle for this form. All "objects" windows,buttons, pictures has a hwnd.
 
have you tried

Code:
Private Sub Form_Open(Cancel As Integer)
docmd.runcommand accmdsizetofitform
End Sub
that does not do the trick either darbid.

what i really want is the extra grey space that is created on the right side of the form to be evenly distributed so you see it on the right and left sides of the form instead. this extra grey space on the left sides of forms is going to be a problem for anyone with a wide screen monitor like mine, or even wider than mine...
 
the other thing i could do here is select all of the controls as a group in VBA, then move them accordingly around on the screen, but i don't know how to select all in VBA. does anyone know how to select controls in VBA?
 
That is going to be a real problem and it is one I have too. I now have people using 1650 screens and my forms are for 1280 screens which means there is a massive right blank part.

From my limited experience the position of something in Access left to right is only done from the left.

What you are looking for is an "align = centre" style and then you just change the size of your form and all you things sit in the middle all the time.

The only way I know to keep equal space on the left and right is to move all your controls.

You could do something wild like have a left blank form. Your real form has your stuff on it and the left one changes size depending on the width of the screen.
 
The only way I know to keep equal space on the left and right is to move all your controls.

You could do something wild like have a left blank form. Your real form has your stuff on it and the left one changes size depending on the width of the screen.
that would work darbid, but this all STILL has to be dynamic! it has to cope with any changes that come up. do you know how to do this? i really don't as of right now...


as i posted before, if I can find a way to SELECT ALL controls on the form in code, i can probably get this done myself. i have all the other tools needed, i just can't get the controls moved!
 
as i posted before, if I can find a way to SELECT ALL controls on the form in code, i can probably get this done myself. i have all the other tools needed, i just can't get the controls moved!
Having a look at the object explorer (I am a learner) your form can give you all the controls on it.

Then you could loop through them all and change their position to the right a little. For example I think the below works to make the controls that i have choose to be null or false.

Code:
For Each ctl In Me.Controls
       Select Case ctl.ControlType
        Case acTextBox, acComboBox
            ctl.Value = Null
        Case acCheckBox
            ctl.Value = False
        End Select
    Next

You could do all this before the form was even visible and nobody would know.
 
Just as a wild idea, could you not place all your controls in an option group frame that fits the dimensions of the form. set the border to none. Then when the form opens and maximises the top left of the option control would normally be 0,0. But you could center horizontally and vertically one the form has resized.

BTW here is a demo on form resizing that might help.

David
 

Attachments

david,

i don't believe that will work because of this extra grey that the form is producing

take a look at the picture i've attached. as you can see, the form width is smaller than the actual width of the picture, which is the width of my monitor. the difference here is filled with grey form background, even though the space is not actually part of the form width itself. i am still working on a solution to this...

i think i've got one, but it is taking time to write the code for it
 

Attachments

  • game.jpg
    game.jpg
    94.3 KB · Views: 143
all that have helped...

i figured out the problem with the form width, but now i need to get the controls centered properly, but they're not moving for me. :rolleyes:

here is the code i'm using:
Code:
Private Sub ButtonListen_Click()

Dim c As Control
Dim player As Object
Set player = Forms!MainSystem!ClientMovie.Object
player.Controls.Pause

DoCmd.OpenForm "listenskills", acDesign, , , , acHidden
Forms!listenskills.Width = Me.WindowWidth

For Each c In Forms!listenskills.Controls
   c.left = c.left + 2880
Next c

DoCmd.Save acForm, "listenskills"
DoCmd.OpenForm "listenskills", acNormal

'DoCmd.OpenForm "ListenSkills"
'Forms!MainSystem!ButtonListen.SpecialEffect = 2


End Sub
a little help please?
 
Just as a wild idea, could you not place all your controls in an option group frame that fits the dimensions of the form. set the border to none. Then when the form opens and maximises the top left of the option control would normally be 0,0. But you could center horizontally and vertically one the form has resized.

BTW here is a demo on form resizing that might help.

David

This is the way to go, i created a Database for work and because everyone uses different resolution then that of my own, i used the modResizeForm module and it worked like a charm. For best results created the database in 640 x 480 resolution. I created mine in 1280 x 1024 Resolution and you loose a bit of clarity with your forms.
 

Users who are viewing this thread

Back
Top Bottom