Solved

Active Resize Question

Posted on 2008-10-24
3
213 Views
Last Modified: 2012-05-05
Experts,

Does anyone use ActiveResize for VB?  It's a tool that automatically resizes a form to fit screen resolution.  I'm finding that the demo version works on some screens but not on others.  Ideas?
0
Comment
Question by:NigelRocks
[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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
Adel87 earned 500 total points
ID: 22802193
instead of wasting your money on off-the-shelve components you can make your own code or use the code in the following link :

http://www.dreamincode.net/forums/showtopic34776.htm

it will simply resize all the controls of the form with respect to the new size of the form. it's simple to use also, you just add the mudule and call the function from the resize event of your form.

Please let me know if you need further assistance.

Regards,
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22805868
I put all this code in its own module and I get a "division by zero" error on this line:

x_size = frm.height / iHeight


What am I missing?

0
 
LVL 2

Assisted Solution

by:Adel87
Adel87 earned 500 total points
ID: 22806223
hi,

it seems you forgot to put the code for the load event of the form, that's why iHeight is not declared.

Please do the following :

'================================================
1- put the following code in the form1_load method
'================================================
Private Sub Form_Load()
    GetLocation Me
    CenterForm Me
    ResizeForm Me
End Sub
'--------------------------------------------------------------------------------------

'================================================
2- put the following code in the form_resize method :
'================================================
Private Sub Form_Resize()
     ResizeControls Me
End Sub
'--------------------------------------------------------------------------------------

'================================================
3- Put the code attached with this post underneath a module
'================================================

'================================================
4- add few components like command buttons and labels with difirent sizes all over the form.
'================================================

'================================================
5- if you need to change the font size also then ,for each componant that needs the font to be change with respect to the form size add the following line in both the Form1_Load and the Form1_Resize events:
'================================================
Label.Font = SetFontSize()
'--------------------------------------------------------------------------------------

Please let me know if you need further assistance.

Regards,
Private List() As Control
Private curr_obj As Object
Private iHeight As Integer
Private iWidth As Integer
Private x_size As Double
Private y_size As Double
'*****************************************************************************************
'                           LICENSE INFORMATION
'*****************************************************************************************
'   FormControl Version 2.0
'   Code module for resizing a form based on screen size, then resizing the
'   controls based on the forms size
'
'   Copyright (C) 2007
'   Richard L. McCutchen
'   Email: richard@psychocoder.net
'   Created: AUG99
'
'   This program is free software: you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation, either version 3 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program.  If not, see <http://www.gnu.org/licenses/>.
'*****************************************************************************************
 
Private Type Control
    Index As Integer
    Name As String
    Left As Integer
    Top As Integer
    width As Integer
    height As Integer
End Type
 
Public Sub ResizeControls(frm As Form)
Dim i As Integer
'   Get ratio of initial form size to current form size
x_size = frm.height / iHeight
y_size = frm.width / iWidth
 
'Loop though all the objects on the form
'Based on the upper bound of the # of controls
For i = 0 To UBound(List)
    'Grad each control individually
    For Each curr_obj In frm
        'Check to make sure its the right control
        If curr_obj.TabIndex = List(i).Index Then
            'Then resize the control
             With curr_obj
                .Left = List(i).Left * y_size
                .width = List(i).width * y_size
                .height = List(i).height * x_size
                .Top = List(i).Top * x_size
             End With
        End If
    'Get the next control
    Next curr_obj
Next i
End Sub
 
Public Function SetFontSize() As Integer
    'Make sure x_size is greater than 0
    If Int(x_size) > 0 Then
    'Set the font size
        SetFontSize = Int(x_size * 8)
    End If
End Function
 
Public Sub GetLocation(frm As Form)
Dim i As Integer
'   Load the current positions of each object into a user defined type array.
'   This information will be used to rescale them in the Resize function.
 
'Loop through each control
For Each curr_obj In frm
'Resize the Array by 1, and preserve
'the original objects in the array
    ReDim Preserve List(i)
    With List(i)
        .Name = curr_obj
        .Index = curr_obj.TabIndex
        .Left = curr_obj.Left
        .Top = curr_obj.Top
        .width = curr_obj.width
        .height = curr_obj.height
    End With
    i = i + 1
Next curr_obj
    
'   This is what the object sizes will be compared to on rescaling.
    iHeight = frm.height
    iWidth = frm.width
End Sub
 
Public Sub CenterForm(frm As Form)
    frm.Move (Screen.width - frm.width) \ 2, (Screen.height - frm.height) \ 2
End Sub
 
Public Sub ResizeForm(frm As Form)
    'Set the forms height
    frm.height = Screen.height / 2
    'Set the forms width
    frm.width = Screen.width / 2
    'Resize all of the controls
    'based on the forms new size
    ResizeControls frm
End Sub

Open in new window

0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bit defender blocks good applications 2 106
Determine Range to Select 5 56
Help me. 3 69
Remove Exif Orientation before adding image to db 9 40
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 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