Results 1 to 3 of 3

Thread: Repositioned objects on form...

  1. #1
    Guest

    Red face

    I'm sure some of you have come across this problem before...

    I've sent my program out to some people for testing, and one person has sent me back a screen shot which shows the form correctly, but all the objects on it have been moved further down and to the right than they should be. This leaves the graphics looking skewed and half of the controls off-screen.

    Does anyone know what the problem could be? Could it be screen resolution?

    Cheers!
    Mafro

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    Cool my guess is as yours..this will help.

    Make sure you do the Assumes>

    ' * Assumes:1. Add Elastic.cls
    ' * 2. Add declaration 'Private El as New class_Elastic'
    ' * 3. Insert string like 'El.init Me' (formload event)
    ' * 4. Insert string like 'El.FormResize Me' (Resize event)
    ' * 5. Press 'F5' and resize form ....
    '
    '****************************************************************


    ' #VBIDEUtils#************************************************************
    ' * Programmer Name : Mikhail Shmukler
    ' * Web Site : http://www.geocities.com/ResearchTriangle/6311/
    ' * E-Mail : [email protected]
    ' * Date : 13/10/98
    ' * Time : 10:24
    ' * Module Name : class_Elastic
    ' * Module Filename : Elastic.cls
    ' **********************************************************************
    ' * Comments :
    ' * This class can change size and location of controls On your form
    ' * 1. Resize form
    ' * 2. Change screen resolution
    ' * Assumes:1. Add Elastic.cls
    ' * 2. Add declaration 'Private El as New class_Elastic'
    ' * 3. Insert string like 'El.init Me' (formload event)
    ' * 4. Insert string like 'El.FormResize Me' (Resize event)
    ' * 5. Press 'F5' and resize form ....
    '
    '****************************************************************

    Option Explicit
    Private nFormHeight As Integer
    Private nFormWidth As Integer
    Private nNumOfControls As Integer
    Private nTop() As Integer
    Private nLeft() As Integer
    Private nHeight() As Integer
    Private nWidth() As Integer
    Private nFontSize() As Integer
    Private nRightMargin() As Integer
    Private bFirstTime As Boolean

    Sub Init(frm As Form, Optional nWindState As Variant)

    Dim I As Integer
    Dim bWinMax As Boolean

    bWinMax = Not IsMissing(nWindState)

    nFormHeight = frm.Height
    nFormWidth = frm.Width
    nNumOfControls = frm.Controls.Count - 1
    bFirstTime = True
    ReDim nTop(nNumOfControls)
    ReDim nLeft(nNumOfControls)
    ReDim nHeight(nNumOfControls)
    ReDim nWidth(nNumOfControls)
    ReDim nFontSize(nNumOfControls)

    ReDim nRightMargin(nNumOfControls)
    On Error Resume Next
    For I = 0 To nNumOfControls
    If TypeOf frm.Controls(I) Is Line Then
    nTop(I) = frm.Controls(I).Y1
    nLeft(I) = frm.Controls(I).X1
    nHeight(I) = frm.Controls(I).Y2
    nWidth(I) = frm.Controls(I).X2
    Else
    nTop(I) = frm.Controls(I).Top
    nLeft(I) = frm.Controls(I).Left
    nHeight(I) = frm.Controls(I).Height
    nWidth(I) = frm.Controls(I).Width
    nFontSize(I) = frm.FontSize
    nRightMargin(I) = frm.Controls(I).RightMargin
    End If
    Next

    If bWinMax Or frm.WindowState = 2 Then ' maxim
    frm.Height = Screen.Height
    frm.Width = Screen.Width
    Else
    frm.Height = frm.Height * Screen.Height / 7290
    frm.Width = frm.Width * Screen.Width / 9690
    End If

    bFirstTime = True

    End Sub

    Sub FormResize(frm As Form)

    Dim I As Integer
    Dim nCaptionSize As Integer
    Dim dRatioX As Double
    Dim dRatioY As Double
    Dim nSaveRedraw As Long

    On Error Resume Next
    nSaveRedraw = frm.AutoRedraw

    frm.AutoRedraw = True

    If bFirstTime Then
    bFirstTime = False
    Exit Sub
    End If

    If frm.Height < nFormHeight / 2 Then frm.Height = nFormHeight / 2

    If frm.Width < nFormWidth / 2 Then frm.Width = nFormWidth / 2
    nCaptionSize = 400
    dRatioY = 1# * (nFormHeight - nCaptionSize) / (frm.Height - nCaptionSize)
    dRatioX = 1# * nFormWidth / frm.Width
    On Error Resume Next ' for comboboxes, timeres and other nonsizible controls

    For I = 0 To nNumOfControls
    If TypeOf frm.Controls(I) Is Line Then
    frm.Controls(I).Y1 = Int(nTop(I) / dRatioY)
    frm.Controls(I).X1 = Int(nLeft(I) / dRatioX)
    frm.Controls(I).Y2 = Int(nHeight(I) / dRatioY)
    frm.Controls(I).X2 = Int(nWidth(I) / dRatioX)
    Else
    frm.Controls(I).Top = Int(nTop(I) / dRatioY)
    frm.Controls(I).Left = Int(nLeft(I) / dRatioX)
    frm.Controls(I).Height = Int(nHeight(I) / dRatioY)
    frm.Controls(I).Width = Int(nWidth(I) / dRatioX)
    frm.Controls(I).FontSize = Int(nFontSize(I) / dRatioX) + Int(nFontSize(I) / dRatioX) Mod 2
    frm.Controls(I).RightMargin = Int(nRightMargin(I) / dRatioY)
    End If
    Next

    frm.AutoRedraw = nSaveRedraw

    End Sub

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest

    Wink Oh, its as simple as that is it??

    Can someone explain exactly what all this code does?
    Can anyone tell me why the controls move themselves around in the first place?

    My program has many forms and is very complex (read: dirty) - so a simpler solution would be preferable..

    Thanks!
    Mafro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width