?
Solved

resolution problem 100 Points

Posted on 2001-08-02
17
Medium Priority
?
157 Views
Last Modified: 2012-05-04
Hi all, I have a form with a graphic image in the middle. The form's properties is set to "maximized". On my monitor the gragphic is centered very nice at 640 X 480. When I view the image on a friends computer with a higher resolution the image shrinks instead of staying in the middle of the screen.

Is there code to force the image on the form to stay centered at different resolutions on other computers ? It is important to have the image on the form remain centered and the form itself to stay maximized.

Any working code would be appreciated for VB 5.0

Thanks
stnic

0
Comment
Question by:stnic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +4
17 Comments
 
LVL 6

Accepted Solution

by:
anthony_glenwright earned 400 total points
ID: 6347196
Put this in your form_load.

Picture1.Move (Me.ScaleWidth - Picture1.ScaleWidth) / 2, (Me.ScaleHeight - Picture1.ScaleHeight) / 2
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6347198
Us the form_resize event (executes even when you don't actually resize it) to move the picture:

Private Sub Form_Resize()

    Picture1.Move (Form1.Width - Picture1.Width) / 2, (Form1.Height - Picture1.Height) / 2

End Sub
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6347204
You can use this code:
Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then Exit Sub
   
    With Image1
        .Top = (Me.ScaleHeight / 2) - (.Height / 2)
        .Left = (Me.ScaleWidth / 2) - (.Width / 2)
    End With
End Sub
0
Independent Software Vendors: 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 3

Expert Comment

by:leojl
ID: 6347246
hi stnic,
try this code.it should use whatever resolution the monitor has.

leo


Private Sub Form_Load()
WindowState = 2
End Sub

Private Sub Form_Click()
scw = Form1.ScaleWidth
sch = Form1.ScaleHeight
pw = Picture1.Width
ph = Picture1.Height
Picture1.Left = (scw - pw) / 2
Picture1.Top = (sch - ph) / 2
End Sub

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6347251
Set the StartUpPosition of the Form in design mode to vbStartUpScreen.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6347255
To clarify:
vbStartUpScreen=2 and it centers the form on the whole screen.
0
 
LVL 3

Expert Comment

by:leojl
ID: 6347263
hi again,

ha ha ha ...3 or 4 good answers while I was in VB.

anthony_glenwright's is a very neat solution.

I keep forgetting "Me.xxxxx".

leo
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6347271
The easy questions always seem very popular (-:
0
 

Author Comment

by:stnic
ID: 6347312
Hi All, I will test all of your responses tonight and then place the program on my friends computer, which ever one works will be posted tomorrow! Thanks to all who participated !

stnic
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6347331
anthony's got the right of it, but with one small change:

Picture1.Move (Me.ScaleWidth - Picture1.Width) / 2, (Me.ScaleHeight - Picture1.Height) / 2
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 6347354
suggest you use Image control show picture, and set property Stretch = True, now the picture will fill all the Image area, just need code:
Private Sub Form_Resize()
   If Me.WindowState = vbMinimized Then Exit Sub
   
   Image1.Move 0, 0, ScaleHeight, ScaleWidth
End Sub
0
 
LVL 3

Expert Comment

by:leojl
ID: 6347459
kd makes a good point
width vs scalewidth for the picture box.

leo
0
 

Author Comment

by:stnic
ID: 6348443
Hi All, what if you have more than one image in a group and they all have to stay centered with the form maximized on monitors with a higher resolution than 640 X 480 ?

Thanks

stnic
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6348625
What do you mean by more than one image in a group?
0
 

Author Comment

by:stnic
ID: 6348904
Hi anthony_glenwright, what i mean is six images (like the first six letters of the alphabet). Each image is placed about an inch from the other in two rows (three per row) forming the center of the screen.

If i had six images how would I change your code to make sure all of the images were centered ? Or does the Picture1 in your code take care of all of this ?

I'm asking because I have no way of testing this until later today at my friends house. I am stuck with this video card that stays on 640 X 480.

Thanks

stnic
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6350062
In that case, cheat:

Put the six image controls into a picture box with all the correct spacing (and centered in said picbox!). Turn the picbox's border off. Now use the centering code for Picture1.
0
 

Author Comment

by:stnic
ID: 6350728
Hi all, Thanks to everyone who commented ! I decided to award the points to anthony_glenwright not only was his the first comment, his code worked for me :)

Until next time!

stnic
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

743 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