Go Back   Access World Forums > Microsoft Access Reference > Sample Databases

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 07-03-2006, 08:57 PM   #1
ssteinke
for what it's worth
 
ssteinke's Avatar
 
Join Date: Aug 2003
Location: Toledo, OH
Posts: 195
Thanks: 0
Thanked 12 Times in 6 Posts
ssteinke
Resize and Center Image Frame

This example shows a way to Resize and Center the image frame to fit the image regardless of the image size. Images larger than the frame will be reduced to fit the frame. Images smaller than the frame will remain their normal size. Simply call the function named fResizeImageFrame().

This also provides a way to apply a border to your pictures at runtime.

You must link to a picture in the image frame in order to use this example.

Scott

EDIT: See below for corrected code
Attached Files
File Type: zip Resize Image Frame.zip (43.0 KB, 2811 views)

__________________
OS: W2k/XP App: A2K

Last edited by ssteinke; 07-06-2006 at 02:47 PM.
ssteinke is offline  
Old 07-06-2006, 06:18 AM   #2
CharlesWilliams
Newly Registered User
 
Join Date: Dec 2004
Posts: 70
Thanks: 2
Thanked 0 Times in 0 Posts
CharlesWilliams is on a distinguished road
RE: Resize and Center Image Frame

Could I get a MS Access 2000 version please?
CharlesWilliams is offline  
Old 07-06-2006, 06:59 AM   #3
ssteinke
for what it's worth
 
ssteinke's Avatar
 
Join Date: Aug 2003
Location: Toledo, OH
Posts: 195
Thanks: 0
Thanked 12 Times in 6 Posts
ssteinke
here ya go

EDIT: See below for corrected code
Attached Files
File Type: zip Resize Image Frame 2000.zip (40.6 KB, 1218 views)

__________________
OS: W2k/XP App: A2K

Last edited by ssteinke; 07-08-2006 at 05:05 PM.
ssteinke is offline  
Old 07-06-2006, 02:45 PM   #4
ssteinke
for what it's worth
 
ssteinke's Avatar
 
Join Date: Aug 2003
Location: Toledo, OH
Posts: 195
Thanks: 0
Thanked 12 Times in 6 Posts
ssteinke
The posted sample works fine for a perfectly square image frame, however, it was pointed out that when a frame is wider than an image that is also wide, the function causes the picture to be adjusted outside the boundary of the frame instead of the frame adjusting to the picture.

The following code fixes the issue by calculating a dimensional percentage of the frame and picture and then comparing the two, essentially giving the desired effect of the frame adjusting to the picture, regardless of the size of either.

THIS IS THE CORRECTED CODE:

Code:
'This function will resize and center an image frame based on the
'dimensions of any image.
Public Function fResizeImageFrame(ctl As Control)
On Error GoTo Err_fResizeImageFrame

    Dim fraLeft As Integer
    Dim fraTop As Integer
    Dim fraHgt As Integer
    Dim fraWdt As Integer
    Dim picHgt As Integer
    Dim picWdt As Integer
    Dim pct As Double
    Dim fra As Double
    Dim pic As Double
    
    'get dimensions of the image frame
    fraLeft = ctl.Left
    fraTop = ctl.Top
    fraHgt = ctl.Height
    fraWdt = ctl.Width
    
    'get dimensions of the image in the frame
    picHgt = ctl.ImageHeight
    picWdt = ctl.ImageWidth

    'get a percent value for the frame and image
    'which is based on the dimensions of each
    fra = fraWdt / fraHgt
    pic = picWdt / picHgt

'pics dimensions smaller than entire frame
    If fraHgt > picHgt And fraWdt > picWdt Then
        'resize frame to fit pic
        ctl.Height = picHgt
        ctl.Width = picWdt
        'center frame
        ctl.Left = fraLeft + ((fraWdt - picWdt) / 2)
        ctl.Top = fraTop + ((fraHgt - picHgt) / 2)
'pics dimensions taller than frame dimensions
    ElseIf pic < fra Then
        'determine percentage the pic is being reduced
        pct = fraHgt / picHgt
        'calculate the new pic width
        picWdt = picWdt * pct
        'resize frame to fit pic
        ctl.Width = fraWdt - (fraWdt - picWdt)
        'center frame
        ctl.Left = fraLeft + ((fraWdt - picWdt) / 2)
'pics dimensions wider than frame dimensions
    ElseIf pic > fra Then
        'determine percentage the pic is being reduced
        pct = fraWdt / picWdt
        'calculate the new pic height
        picHgt = picHgt * pct
        'resize frame to fit pic
        ctl.Height = fraHgt - (fraHgt - picHgt)
        'center frame
        ctl.Top = fraTop + ((fraHgt - picHgt) / 2)
    End If

Exit_fResizeImageFrame:
    Exit Function
Err_fResizeImageFrame:
    MsgBox Err.Description, vbCritical, "Error " & Err.Number
    Resume Exit_fResizeImageFrame
End Function
To Call:
Code:
Call fResizeImageFrame(Me.ImageFrameName)

__________________
OS: W2k/XP App: A2K
ssteinke is offline  
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button Form Resize GUIDO22 Forms 0 04-27-2005 11:50 PM




All times are GMT -8. The time now is 11:38 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World