• (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5

Resize Form & Controls For Screen Size - VB6 Rate Topic: ***** 1 Votes

#61 BasantRajpurohit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-September 14

Posted 16 September 2014 - 07:13 AM

View Postpmabres, on 28 February 2012 - 11:15 PM, said:

Forgot the attachment.

Here it is


i have Devlop a project at my leptop Screen Resolution 1366*768
i add your module for Resize control on difrench Screen Resolution.
but some part of right side does not show on my leptop in any resolution
left part is also hide in my original screen resolution 1366*768
i have attach screen shot without module run and after run module

Please see screen shot and help me how can i solve it

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#62 andrewsw  Icon User is online

  • Beach ready
  • member icon

Reputation: 5468
  • View blog
  • Posts: 21,517
  • Joined: 12-December 12

Posted 16 September 2014 - 07:44 AM

Your form is very cluttered; there is little space between controls and the controls are not evenly distributed. The code in this tutorial is not magic code; some forms are not suitable to be resized, or can only do so in a very limited, and controlled, way.

BTW There is a Reply button further down the page, you don't have to quote a previous post every time.

This post has been edited by andrewsw: 16 September 2014 - 07:45 AM

Was This Post Helpful? 0
  • +
  • -

#63 pmabres  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-February 12

Posted 16 September 2014 - 07:56 AM

View PostBasantRajpurohit, on 16 September 2014 - 07:13 AM, said:

View Postpmabres, on 28 February 2012 - 11:15 PM, said:

Forgot the attachment.

Here it is


i have Devlop a project at my leptop Screen Resolution 1366*768
i add your module for Resize control on difrench Screen Resolution.
but some part of right side does not show on my leptop in any resolution
left part is also hide in my original screen resolution 1366*768
i have attach screen shot without module run and after run module

Please see screen shot and help me how can i solve it


Hello i'll upload you an example with the code working, its a bit old so i don't know if i left it broke or not. If its not working just tell me. You have too many controls in your screen, also it seems that you're not running the code when form resizes. Try to organize better your visual part, and distribute the controls in tabs in a sstab control. With that example you can work it.
Attached File  formresizewithsstab.zip (4.79K)
Number of downloads: 220
Was This Post Helpful? 0
  • +
  • -

#64 yhj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-May 15

Posted 15 May 2015 - 01:54 AM

View Postshad0w3rz, on 10 October 2007 - 09:24 PM, said:

what program i need to run this file?


I thank you for your code. It help me a lot (my english is not so good !)
I had nethertheless a problem
All objects on the form have not all the attribute needed and cause errors (timer, menu, commondialog, etc..). it is necessary to not use them in the loop
The only solution i have found is to use the tag propertie to test the object before the loop
XX = curr_obj.Tag
If XX = "**" Then (** is writen only for controls having all the necessary properties)
-> execute the code
end if
This works for my project but i suspect that there are better ways to do the job
What do you think about that

Sincerely yours

yhj
Was This Post Helpful? 0
  • +
  • -

#65 andrewsw  Icon User is online

  • Beach ready
  • member icon

Reputation: 5468
  • View blog
  • Posts: 21,517
  • Joined: 12-December 12

Posted 15 May 2015 - 02:17 AM

That quote is confusing as it has nothing to do with your post. Just use the REPLY button towards the bottom of the page.

I haven't read this thread, or studied the tutorial in any depth, but using the Tag property seems reasonable to me. It also means that you can remove the Tag for any controls that you decide don't need to be resized.
Was This Post Helpful? 0
  • +
  • -

#66 Alphaek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-January 16

Posted 18 January 2016 - 08:51 AM

HI
I cannot implement this code. Can someone who has used this code post the complete code with a sample form. Thank you.
This is what I have done so far. Created a sample form and put the re-sizing code in the module. Still won't work I am getting the same errors as the other users.
Was This Post Helpful? 0
  • +
  • -

#67 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 11495
  • View blog
  • Posts: 45,375
  • Joined: 12-June 08

Posted 18 January 2016 - 08:56 AM

Please open a thread in the VB6 help section explaining your current problems, pasting any error messages, and posting your current code that causes those errors (don't forget the code tags!).
Was This Post Helpful? 0
  • +
  • -

#68 pmabres  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-February 12

Posted 18 January 2016 - 09:01 AM

View PostAlphaek, on 18 January 2016 - 08:51 AM, said:

HI
I cannot implement this code. Can someone who has used this code post the complete code with a sample form. Thank you.
This is what I have done so far. Created a sample form and put the re-sizing code in the module. Still won't work I am getting the same errors as the other users.


Hello Alphaek, you have my zip file attached few posts above yours, doesn't that works for you?
Was This Post Helpful? 0
  • +
  • -

#69 Alphaek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-January 16

Posted 21 January 2016 - 06:39 AM

View Postyhj, on 15 May 2015 - 01:54 AM, said:

View Postshad0w3rz, on 10 October 2007 - 09:24 PM, said:

what program i need to run this file?


I thank you for your code. It help me a lot (my english is not so good !)
I had nethertheless a problem
All objects on the form have not all the attribute needed and cause errors (timer, menu, commondialog, etc..). it is necessary to not use them in the loop
The only solution i have found is to use the tag propertie to test the object before the loop
XX = curr_obj.Tag
If XX = "**" Then (** is writen only for controls having all the necessary properties)
-> execute the code
end if
This works for my project but i suspect that there are better ways to do the job
What do you think about that

Sincerely yours

yhj


View PostAlphaek, on 21 January 2016 - 06:36 AM, said:

View Postyhj, on 15 May 2015 - 01:54 AM, said:

View Postshad0w3rz, on 10 October 2007 - 09:24 PM, said:

what program i need to run this file?


I thank you for your code. It help me a lot (my english is not so good !)
I had nethertheless a problem
All objects on the form have not all the attribute needed and cause errors (timer, menu, commondialog, etc..). it is necessary to not use them in the loop
The only solution i have found is to use the tag propertie to test the object before the loop
XX = curr_obj.Tag
If XX = "**" Then (** is writen only for controls having all the necessary properties)
-> execute the code
end if
This works for my project but i suspect that there are better ways to do the job
What do you think about that

Sincerely yours

yhj


Hi yhj
I am a complete beginner. Can you please go step by step how you made your program work. What you put in form and module. Thanks
Alphaek
Was This Post Helpful? 0
  • +
  • -

#70 Alphaek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-January 16

Posted 21 January 2016 - 06:45 AM

[quote name='pmabres' date='16 September 2014 - 07:56 AM' timestamp='1410879402' post='2052432']

View PostBasantRajpurohit, on 16 September 2014 - 07:13 AM, said:

View Postpmabres, on 28 February 2012 - 11:15 PM, said:

Forgot the attachment.

Here it is


i have Devlop a project at my leptop Screen Resolution 1366*768
i add your module for Resize control on difrench Screen Resolution.
but some part of right side does not show on my leptop in any resolution
left part is also hide in my original screen resolution 1366*768
i have attach screen shot without module run and after run module

Please see screen shot and help me how can i solve it


Hello i'll upload you an example with the code working, its a bit old so i don't know if i left it broke or not. If its not working just tell me. You have too many controls in your screen, also it seems that you're not running the code when form resizes. Try to organize better your visual part, and distribute the controls in tabs in a sstab control. With that example you can work it.
Attached File  formresizewithsstab.zip (4.79K)
Number of downloads: 220


Hi
Your zip file downloads fine. But it will not unzip. Can you please download this file and unzip it to see the problem. Then send it again or put the full code in this section. What you put in the form1 and the module. Thanks
Alphaek
Was This Post Helpful? 0
  • +
  • -

#71 pmabres  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-February 12

Posted 21 January 2016 - 07:11 AM

This is the modResolution.bas file code.

Attribute VB_Name = "Module1"
Option Explicit
Private List() As Controles
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: [email protected]
'   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/>.
'*****************************************************************************************
Public Const RESIZEDEFAULT As String = "RESIZUPELEFTWIDTH"
Public Const RESIZEALL As String = "RESIZEALL"
Public Const NORESIZE As String = "NORESIZE"
Public Const RESIZEUP As String = "RESIZEUP"
Public Const RESIZELEFT As String = "RESIZELEFT"
Public Const RESIZEUPLEFT As String = "RESIZEUPLEFT"
Public Const RESIZEUPWIDTH As String = "RESIZUPWIDTH"
Public Const RESIZELEFTWIDTH As String = "RESIZUPLEFTWIDTH"
Public Const RESIZEUPLEFTWIDTH As String = "RESIZUPELEFTWIDTH"

Private Const Line = "Line"
Private Const Menu = "Menu"
Private Const SSTab = "SSTab"
Private Const Frame = "Frame"
Private Const Label = "Label"
Private Const Timer = "Timer"
Private Const TextBox = "TextBox"
Private Const ComboBox = "ComboBox"
Private Const CheckBox = "CheckBox"
Private Const TreeView = "TreeView"
Private Const ListView = "ListView"
Private Const MaskEdBox = "MaskEdBox"
Private Const ImageList = "ImageList"
Private Const RichTextBox = "RichTextBox"
Private Const CommandButton = "CommandButton"

Private Type Controles
    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, b As Integer
  Dim strTag As String
  Dim curr_obj As Control

  On Error Resume Next
'   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.Controls
      strTag = UCase(curr_obj.Tag)
      'If TypeOf curr_obj Is Menu Then
    ' ignore menu controls
      'Else
      If strTag <> NORESIZE Then
        If curr_obj.TabIndex = List(i).Index Then
          'Then resize the control
          With curr_obj
            If TypeName(.Container) = "SSTab" Then
                For b = 0 To .Container.Tabs - 1
                    .Container.Tab = b
                    If .Left > 0 Then
                        Exit For
                    End If
                Next
            End If
           
            Select Case strTag
              Case RESIZEALL
                .Left = List(i).Left * y_size
                .width = List(i).width * y_size
                .height = List(i).height * x_size
                .Top = List(i).Top * x_size
              Case RESIZELEFT
                .Left = List(i).Left * y_size
              Case RESIZEUPLEFTWIDTH
                .Top = List(i).Top * x_size
                .width = List(i).width * y_size
                .Left = List(i).Left * y_size
              Case RESIZEUPWIDTH
                .Top = List(i).Top * x_size
                .width = List(i).width * y_size
              Case RESIZELEFTWIDTH
                .Left = List(i).Left * y_size
                .width = List(i).width * y_size
              Case RESIZEUPLEFT
                .Left = List(i).Left * y_size
                .Top = List(i).Top * x_size
              Case RESIZEUP
                .Top = List(i).Top * x_size
              Case Else
            End Select
          End With
        End If
      End If
    Next curr_obj
  Next i
End Sub

Public Function SetFontSize() As Integer
  On Error Resume Next
  
    '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, b As Integer
  Dim curr_obj As Control
'   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
On Error Resume Next
For Each curr_obj In frm.Controls
'Resize the Array by 1, and preserve
'the original objects in the array
    If UCase(curr_obj.Tag) <> UCase("NORESIZE") Then
        ReDim Preserve List(i)
        With List(i)
            If TypeName(curr_obj.Container) = "SSTab" Then
                For b = 0 To curr_obj.Container.Tabs - 1
                    curr_obj.Container.Tab = b
                    If curr_obj.Left > 0 Then
                        Exit For
                    End If
                Next
            End If
            .Name = curr_obj.Name
            .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
    End If
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)
  On Error Resume Next
  frm.Move (Screen.width - frm.width) \ 2, (Screen.height - frm.height) \ 2
End Sub

Public Sub ResizeForm(frm As Form)
  On Error Resume Next
    'Set the forms height
    frm.height = Screen.height
    'Set the forms width
    frm.width = Screen.width
    'Resize all of the controls
    'based on the forms new size
    ResizeControls frm
End Sub

Public Sub SetNoResize(ByRef frm As Form) 'this function set noresize to all controls that are not resizeable.Ej: Timers
  Dim ctl As Control
  On Error Resume Next
  
  For Each ctl In frm.Controls
    Select Case UCase(TypeName(ctl))
      Case UCase(Timer)
        ctl.Tag = NORESIZE
      Case UCase(Menu)
        ctl.Tag = NORESIZE
      Case UCase(ImageList)
        ctl.Tag = NORESIZE
      Case UCase(Line)
        ctl.Tag = NORESIZE
    End Select
  Next
End Sub


Public Sub SetResize(ByRef frm As Form, Optional ByVal strResizeType As String, Optional ByVal strCtrlType As String)  'This function sets the default resize to the controls in the form
  Dim ctl As Control
  Dim strReType As String
  On Error Resume Next

  ' you can pass through strCtrlType (strType) these parameters: Typename(object) or just the string with the type of the object you want to apply the changes
  If strResizeType <> "" Then
    strReType = strResizeType
  Else
    strReType = RESIZEDEFAULT
  End If

  If strCtrlType <> "" Then
    For Each ctl In frm.Controls
      Select Case True
        Case TypeName(ctl) = strCtrlType
          ctl.Tag = strReType
      End Select
    Next
  Else
    For Each ctl In frm.Controls
      If strResizeType <> "" Then ' Resize all controls to this type
        ctl.Tag = strReType
      Else
     'Defaults RESIZES
        Select Case UCase(TypeName(ctl))
          Case UCase(CommandButton)
            ctl.Tag = strReType
          Case UCase(ListView)
            ctl.Tag = RESIZEALL
          Case UCase(SSTab)
            ctl.Tag = RESIZEALL
          Case UCase(TextBox)
            ctl.Tag = strReType
          Case UCase(ComboBox)
            ctl.Tag = strReType
          Case UCase(Frame)
            ctl.Tag = RESIZEALL
          Case UCase(CheckBox)
            ctl.Tag = RESIZEUPLEFT
          Case UCase(TreeView)
            ctl.Tag = RESIZEALL
          Case UCase(MaskEdBox)
            ctl.Tag = strReType
          Case UCase(Label)
            If ctl.Caption <> "" Then
              ctl.Tag = RESIZEUPLEFT
            Else
              ctl.Tag = strReType
            End If
          Case UCase(RichTextBox)
            ctl.Tag = RESIZEALL
          Case Else
            ctl.Tag = strReType
        End Select
      End If
    Next
  End If
  SetNoResize frm ' Execute noresize to establish wich controls do not resize

End Sub






And this is the full Form1.frm code

VERSION 5.00
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "tabctl32.ocx"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command4 
      Caption         =   "Command4"
      Height          =   465
      Left            =   405
      TabIndex        =   6
      Top             =   180
      Width           =   420
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   735
      Left            =   180
      TabIndex        =   5
      Top             =   990
      Width           =   735
   End
   Begin TabDlg.SSTab SSTab1 
      Height          =   2220
      Left            =   1170
      TabIndex        =   0
      Top             =   495
      Width           =   3300
      _ExtentX        =   5821
      _ExtentY        =   3916
      _Version        =   393216
      TabHeight       =   520
      TabCaption(0)   =   "Tab 0"
      TabPicture(0)   =   "Form1.frx":0000
      Tab(0).ControlEnabled=   -1  'True
      Tab(0).Control(0)=   "Frame2"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).ControlCount=   1
      TabCaption(1)   =   "Tab 1"
      TabPicture(1)   =   "Form1.frx":001C
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "Command3"
      Tab(1).Control(1)=   "Command2"
      Tab(1).ControlCount=   2
      TabCaption(2)   =   "Tab 2"
      TabPicture(2)   =   "Form1.frx":0038
      Tab(2).ControlEnabled=   0   'False
      Tab(2).ControlCount=   0
      Begin VB.Frame Frame2 
         Caption         =   "Frame1"
         Height          =   735
         Left            =   1125
         TabIndex        =   3
         Top             =   990
         Width           =   1590
         Begin VB.TextBox Text5 
            Height          =   285
            Left            =   360
            TabIndex        =   4
            Text            =   "Text3"
            Top             =   360
            Width           =   690
         End
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Command3"
         Height          =   375
         Left            =   -74460
         TabIndex        =   2
         Top             =   945
         Width           =   870
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Command2"
         Height          =   420
         Left            =   -73335
         TabIndex        =   1
         Top             =   945
         Width           =   960
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Sub command1_click()
    SetResize Me
    GetLocation Me
    SSTab1.Tab = 0
End Sub

Private Sub Form_Resize()
    Dim i As Integer
    
    i = SSTab1.Tab
    LockWindowUpdate Me.hWnd
    ResizeControls Me
    LockWindowUpdate 0
    Dim ctrl As Control
    SSTab1.Tab = i
End Sub




if you create a file Form1.frm and import the frm into VB you'll be able to see the propperly formated form.

Notice that this following code:
Private Sub command1_click()
    SetResize Me
    GetLocation Me
    SSTab1.Tab = 0
End Sub



Can also be put in the form_load to perform this action automatically.
The SetResize method will set the default type of resize to all controls
The GetLocation will obtain the initial resolution of the form.

When you rezise the form, all the componens within the SStab will mantain their propper aspect ratio depending on how you define them.
You can also change a control.tag to some of these constant to behave differently depending on how you want them to be resized.
yourControl.Tag = RESIZEDEFAULT will resize the up,left position and the with, along with the form
yourControl.Tag = RESIZEALL will resize the up,left position and with,height along with the form
yourControl.Tag = NORESIZE wont resize anything and will stay the same (ex, timers)
yourControl.Tag = RESIZEUP will resize just the up property.
yourControl.Tag = RESIZELEFT will resize just the left property
yourControl.Tag = RESIZEUPLEFT will resize just both up and left property
yourControl.Tag = RESIZEUPWIDTH will resize up and width
yourControl.Tag = RESIZELEFTWIDTH will resize the left and width
yourControl.Tag = RESIZEUPLEFTWIDTH will resize the up,left, and width ( this is the default)

in order to these tags to take effect you to call ResizeControls Me
after in any point that you want.
The most common way is to use this on the Form_Resize event.

Im not developing anymore in VB6 so sorry but i don't have the tools to run any of this code.
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5