Page 2 of 2 FirstFirst 12
Results 41 to 72 of 72

Thread: Resizing form and textboxes ...

  1. #41
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    Attached is a complete version (for my purposes anyway) after playing around with everyone's code submitted in this thread. Most of it is actually DaveBo's last class submitted with Marty's fontsize bit added to it. I just added an optional argument to the resizing method that represents the default ScaleWidth of the form. Pass this, and the fonts resize as well. Combos and SSTabs are good too from the testing I did. cheers
    Attached Files Attached Files
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  2. #42
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by ahara
    Attached is a complete version (for my purposes anyway) after playing around with everyone's code submitted in this thread. Most of it is actually DaveBo's last class submitted with Marty's fontsize bit added to it. I just added an optional argument to the resizing method that represents the default ScaleWidth of the form. Pass this, and the fonts resize as well. Combos and SSTabs are good too from the testing I did. cheers
    Hmm I was not gonna use the class...I just wanted the methods though. You guys got it working for SSTabs and combos too ????

    Should I just use the class...I did not want to but if there isn't just the methods I guess I'll have to use the class?

    Marty ?

    Jon

  3. #43
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    as a test, I just copied the methods into a form and simply called them - still works. I only wanted it wrapped up in a class because I plan on reusing this frequently. And yes it does work for combos and SSTabs (it won't change the height of the combo, but it adjusts the width)
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  4. #44
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by ahara
    as a test, I just copied the methods into a form and simply called them - still works. I only wanted it wrapped up in a class because I plan on reusing this frequently. And yes it does work for combos and SSTabs (it won't change the height of the combo, but it adjusts the width)
    ya i was playing with it.
    seems to have done the trick..this thread got better

  5. #45
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    I've noticed when using this code with the SmartMenu control www.vbsmart.com. That it fails...well it works but it hides the smartmenu...just an FYI.

    Jon

  6. #46
    Hyperactive Member
    Join Date
    Mar 2003
    Location
    Greece, Salonica
    Posts
    473
    Originally posted by ahara
    Attached is a complete version (for my purposes anyway) after playing around with everyone's code submitted in this thread. Most of it is actually DaveBo's last class submitted with Marty's fontsize bit added to it. I just added an optional argument to the resizing method that represents the default ScaleWidth of the form. Pass this, and the fonts resize as well. Combos and SSTabs are good too from the testing I did. cheers
    Ummm...
    Sorry for doing like a n00b, but how do i use that?

  7. #47
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    slap this into any form that has controls (after importing the class into the project)

    VB Code:
    1. Private mobjResizer As FormResizer
    2.  
    3. Private Sub Form_Resize()
    4.     Dim defScaleWidth As Integer
    5.     defScaleWidth = Me.ScaleWidth
    6.     mobjResizer.ResizeControls Me, defScaleWidth
    7.  
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.  
    12.     Set mobjResizer = New FormResizer
    13.     mobjResizer.InitResizeArray Me
    14.    
    15.    
    16. End Sub

    cheers
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  8. #48
    Addicted Member
    Join Date
    Aug 2002
    Location
    Alberta, Canada
    Posts
    138
    this seems to make my text smaller when form is max and text bigger when form gets smaller.... ?? how come?
    Last edited by Jon_G; Oct 22nd, 2004 at 12:20 AM.
    Jon_G
    AKA Phil From Marketing
    **************************************
    Insert Something Memorable And Witty Here.
    **************************************

  9. #49
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74

    Re: Resizing form and textboxes ...

    I've tried using the class and incorporating it into my program but i kept on getting this error message.

    ____________________________
    -Compile error: -
    -User-defined type not defined. -
    _____________________________

    what should i do?

    _________________________________
    Public Sub InitResizeArray(objForm As Form)

    Dim I As Integer
    Dim LeftOffset As Long

    On Error Resume Next

    ReDim mProportionsArray(0 To objForm.Controls.Count - 1)

    For I = 0 To objForm.Controls.Count - 1
    With mProportionsArray(I)
    .Name = objForm.Controls(I).Name
    .Move = True
    .Resize = True

    .HeightProportions = objForm.Controls(I).Height / objForm.ScaleHeight
    .WidthProportions = objForm.Controls(I).Width / objForm.ScaleWidth
    .TopProportions = objForm.Controls(I).Top / objForm.ScaleHeight

    ' Have to be a little careful with .Left here. Controls on an SSTab
    ' control have -75000 added to their .Left prop to make them invisible.
    LeftOffset = 0
    If TypeOf objForm.Controls(I).Container Is SSTab _
    And objForm.Controls(I).Left < 0 Then LeftOffset = 75000
    .LeftProportions = (objForm.Controls(I).Left + LeftOffset) / objForm.ScaleWidth
    End With
    Next I

    End Sub________________________________________

  10. #50
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Resizing form and textboxes ...

    You don't have SSTab control included into your project, thus you get the error. I guess you could remove that line without having any trouble.

  11. #51
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74

    Re: Resizing form and textboxes ...

    i'm sorry but what is SSTab?

    thanks

  12. #52
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Resizing form and textboxes ...

    Quote Originally Posted by dy1jaw
    i'm sorry but what is SSTab?

    thanks
    It is the Microsoft Tabbed Dialog Control 6.0 found under Project|Components.

  13. #53
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Resizing form and textboxes ...

    Or just add this control to your form.
    Attached Files Attached Files

  14. #54
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Resizing form and textboxes ...

    Quote Originally Posted by shragel
    Or just add this control to your form.

    I would try your control but unfortunately I don't run complied projects without looking at the code first. Sorry
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  15. #55
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Resizing form and textboxes ...

    So dont use it

  16. #56
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Resizing form and textboxes ...

    Quote Originally Posted by shragel
    So dont use it

    There are other alternatives
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  17. #57
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Resizing form and textboxes ...

    The problem with the alternative is it doesn't handle combo boxes, and the sstab control.

  18. #58
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Resizing form and textboxes ...

    Quote Originally Posted by shragel
    The problem with the alternative is it doesn't handle combo boxes, and the sstab control.

    Maybe you should take a look at this post

    Here is the link to the entire post
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  19. #59
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Resizing form and textboxes ...

    Attached is an OCX (source included) I made a while back. I haven't tested it with an SS tab but aside from that, it seems to have work in every other situation I have tried. Just compile it and drop it on a form. It will do the rest.
    Attached Files Attached Files

  20. #60
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Resizing form and textboxes ...

    This one I will take a look at as it includes source. Thanks MarkT

  21. #61
    Lively Member
    Join Date
    Sep 2005
    Posts
    82

    Re: Resizing form and textboxes ...

    Just for an idea, it is wiser to make a form scrollable rather than making controls tiny when you resize a form a bit small after a certain level of scale. It may also be a challenge, I use scrollable forms in my projects.

  22. #62
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: Resizing form and textboxes ...

    i know this is an older thread but why won't this code work for images?

  23. #63
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: Resizing form and textboxes ...

    o, i see, i need the stretch property of the image set to true

  24. #64
    Addicted Member
    Join Date
    Mar 2007
    Posts
    178

    Re: Resizing form and textboxes ...

    Dont know if anybody still replies to this post. First of all, I want the form to expand maximum when the form first loads. That possible? How?

    Second, are there any explanation to what the code means? I dont understand how it works at all. Here is the code, although I integrated some other code into it about the combo box problem:

    Code:
    Option Explicit
    
    
    Private Type CtrlProportions
        HeightProportions As Single
        WidthProportions As Single
        TopProportions As Single
        LeftProportions As Single
    End Type
    
    Dim ProportionsArray() As CtrlProportions
    
    Sub InitResizeArray()
    
        Dim I As Integer
        
        On Error Resume Next
        
        ReDim ProportionsArray(0 To Controls.Count - 1)
        
        For I = 0 To Controls.Count - 1
            With ProportionsArray(I)
                .HeightProportions = Controls(I).Height / ScaleHeight
                .WidthProportions = Controls(I).Width / ScaleWidth
                .TopProportions = Controls(I).Top / ScaleHeight
                .LeftProportions = Controls(I).Left / ScaleWidth
            End With
        Next I
        
    End Sub
    Public Sub ResizeControls()
    Dim I As Integer
    On Error Resume Next
    For I = 0 To Controls.Count - 1
    ' move and resize controls
    Controls(I).Left = ProportionsArray(I).LeftProportions * Me.ScaleWidth
    Controls(I).Top = ProportionsArray(I).TopProportions * Me.ScaleHeight
    Controls(I).Width = ProportionsArray(I).WidthProportions * Me.ScaleWidth
    Controls(I).Height = ProportionsArray(I).HeightProportions * Me.ScaleHeight
    Next I
    
    End Sub
    'Form initialize event
    Private Sub Form_Initialize()
    
        InitResizeArray
        
    End Sub
    
    'Form resize event
    Sub Form_Resize()
    
        ResizeControls
        End Sub

  25. #65
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Resizing form and textboxes ...

    Does this ocx work with MDI forms and child forms?

    If so a quick explanation would be great how to impliment this.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  26. #66
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Resizing form and textboxes ...

    Ok, I have been using MartinLiss's Form Resize code for a long time and lately have encountered a few issues that I have corrected. Most users may never see the issue I have encountered. These issues were due to subclassing controls on the form being resized. Here are the new code changes:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type CtrlProportions
    4.     HeightProportions As Single
    5.     WidthProportions As Single
    6.     TopProportions As Single
    7.     LeftProportions As Single
    8. End Type
    9.  
    10. Dim ProportionsArray() As CtrlProportions
    11.  
    12. ' 20080302RJ
    13.  
    14. Dim ArrayInitialized As Boolean
    15. Dim FormScaleMode As Integer
    16.  
    17.  
    18. Private Sub mInitResizeArray(frm As Object)
    19. ' Called from Form_Initialize
    20.  
    21. Dim I As Integer
    22.    
    23.     On Error Resume Next
    24.    
    25.     ' 20080302RJ
    26.     ' The form's Load and Resize events will be invoked after execution of this statement
    27.    
    28.     ReDim ProportionsArray(0 To frm.Controls.Count - 1)
    29.    
    30.     ' We will return here after the form's Load and Resize events have been executed.
    31.     ' Since the Form's Resize event will call mResizeControls we had to take precautions in that
    32.     ' sub not to do anything till we have finished this routine. So if ArrayInitialized = false
    33.     ' the mResizeControls will just exit without attempting to do anything and we will return here.
    34.    
    35.     ' Save the form's scale mode because if the app does subclassing the scale mode will change to pixels
    36.     ' then when we attempt to move it we will mess up the form if we don't change it back to the
    37.     ' original value that the proportion calculation were made with.
    38.    
    39.     FormScaleMode = frm.ScaleMode
    40.    
    41.     For I = 0 To frm.Controls.Count - 1
    42.    
    43.         With ProportionsArray(I)
    44.             .HeightProportions = frm.Controls(I).Height / frm.ScaleHeight
    45.             .WidthProportions = frm.Controls(I).Width / frm.ScaleWidth
    46.             .TopProportions = frm.Controls(I).Top / frm.ScaleHeight
    47.             .LeftProportions = frm.Controls(I).Left / frm.ScaleWidth
    48.         End With
    49.        
    50.     Next I
    51.    
    52.     ArrayInitialized = True
    53.    
    54. End Sub
    55.  
    56. Private Sub mResizeControls(frm As Object)
    57. Dim I As Long
    58. Dim ctl As Control
    59. ' Called from Form_Resize
    60.  
    61.     ' 20080302RJ
    62.     ' Added to insure that we don't attempt to process the form before it is loaded.
    63.     ' When mInitResizeArray is called in the form's Initialize event the first time it accesses
    64.     ' any object/method of the form then Form's Load and Resize Event are invoked before we finish the
    65.     ' mInitResizeArray sub and we will get here before we have initialized the ProportionsArray array.
    66.     ' This causes weird effects on the calling form in certain instances because the array will be full
    67.     ' of zeros and all controls will be relocated to the top of the container they are in if we allow this
    68.     ' routine to operate.
    69.    
    70.     If Not ArrayInitialized Then Exit Sub ' Return to mInitResizeArray sub
    71.    
    72.     On Error Resume Next
    73.        
    74.     ' Return the original scale mode of the form because this is the mode that was used
    75.     ' to calculate the proportions.
    76.    
    77.     frm.ScaleMode = FormScaleMode
    78.    
    79.     For I = LBound(ProportionsArray) To UBound(ProportionsArray) ' 20080302RJ
    80. '    For I = 0 To frm.Controls.Count - 1
    81.    
    82.         Set ctl = frm.Controls(I)
    83.        
    84.         ' 20060403RJ
    85.         ' if we don't want a control to be resized it's tag field will contain "NoResize"
    86.        
    87.         If LCase(ctl.Tag) <> LCase("NoResize") Then
    88.  
    89.             With ProportionsArray(I)
    90.                 ' move and resize controls
    91.                 ctl.Move CLng(.LeftProportions * frm.ScaleWidth), _
    92.                 CLng(.TopProportions * frm.ScaleHeight), _
    93.                 CLng(.WidthProportions * frm.ScaleWidth), _
    94.                 CLng(.HeightProportions * frm.ScaleHeight)
    95.             End With
    96.  
    97.         End If
    98.  
    99.      Next I
    100.      
    101.      Set ctl = Nothing
    102.      
    103. End Sub
    104.  
    105. Public Sub InitResizeArray(frm As Object)
    106.     mInitResizeArray frm
    107. End Sub
    108.  
    109. Public Sub ResizeControls(frm As Object)
    110.     mResizeControls frm
    111. End Sub
    Last edited by randem; Mar 3rd, 2008 at 01:43 AM.

  27. #67
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Resizing form and textboxes ...

    This is a control.

    Here is the code.


    vb Code:
    1. Private Declare Function LockWindowUpdate Lib "user32" _
    2.     (ByVal hwnd As Long) As Long
    3.  
    4. Dim lpara As Long
    5. Private Const CB_SETITEMHEIGHT = &H153
    6.  
    7. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    8. (ByVal hwnd As Long, ByVal wMsg As Long, _
    9. ByVal wParam As Long, lParam As Any) As Long
    10.  
    11.  
    12. Public Reset As Boolean
    13.  
    14. ' if True, also fonts are resized
    15. 'Public ResizeFont As Boolean
    16. ' if True, form's height/width ratio is preserved
    17. Public KeepRatio As Boolean
    18.  
    19. Private Type TControlInfo
    20.     ctrl As Control
    21.     Left As Single
    22.     Top As Single
    23.     Width As Single
    24.     Height As Single
    25.     FontSize As Single
    26. End Type
    27.  
    28. ' this array holds the original position
    29. ' and size of all controls on parent form
    30. Dim Controls() As TControlInfo
    31.  
    32. ' a reference to the parent form
    33. Private WithEvents ParentForm As Form
    34. ' parent form's size at load time
    35. Private ParentWidth As Single
    36. Private ParentHeight As Single
    37. ' ratio of original height/width
    38. Private HeightWidthRatio As Single
    39. 'Default Property Values:
    40. Const m_def_ResizeFont = 0
    41. 'Property Variables:
    42. Dim m_ResizeFont As Boolean
    43.  
    44. Sub LockWindow(hwnd As Long)
    45.     LockWindowUpdate hwnd
    46. End Sub
    47.  
    48. Sub UnlockWindow()
    49.     LockWindowUpdate 0
    50. End Sub
    51.  
    52. Private Sub ParentForm_Activate()
    53. On Error Resume Next
    54. ParentForm.Left = GetSetting(App.EXEName, ParentForm.Name, "Left", ParentForm.Left)
    55. ParentForm.Top = GetSetting(App.EXEName, ParentForm.Name, "Top", ParentForm.Top)
    56. ParentForm.Height = GetSetting(App.EXEName, ParentForm.Name, "Height", ParentForm.Height)
    57. ParentForm.Width = GetSetting(App.EXEName, ParentForm.Name, "Width", ParentForm.Width)
    58. End Sub
    59.  
    60. Private Sub ParentForm_Load()
    61.     ' the ParentWidth variable works as a flag
    62.     ParentWidth = 0
    63.     ' save original ratio
    64.     HeightWidthRatio = ParentForm.Height / ParentForm.Width
    65.  
    66. End Sub
    67. Private Sub ParentForm_Unload(Cancel As Integer)
    68.  
    69. If Not ParentForm.WindowState = vbMinimized Then
    70.  
    71.     If ParentForm.Left > -1000 Then SaveSetting App.EXEName, ParentForm.Name, "Left", ParentForm.Left
    72.  
    73.     If ParentForm.Top > -1000 Then SaveSetting App.EXEName, ParentForm.Name, "Top", ParentForm.Top
    74.  
    75.     If ParentForm.Height > 1000 Then SaveSetting App.EXEName, ParentForm.Name, "Height", ParentForm.Height
    76.  
    77.     If ParentForm.Width > 1000 Then SaveSetting App.EXEName, ParentForm.Name, "Width", ParentForm.Width
    78. End If
    79.  
    80. On Error Resume Next
    81.  
    82. If Reset = True Then DeleteSetting (App.EXEName)
    83. End Sub
    84.  
    85. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    86.      m_ResizeFont = PropBag.ReadProperty("ResizeFont", m_def_ResizeFont)
    87.    If Ambient.UserMode = False Then Exit Sub
    88.     ' store a reference to the parent form and
    89.     ' start receiving events
    90.     Set ParentForm = Parent
    91. End Sub
    92.  
    93. Private Sub UserControl_Resize()
    94.     ' refuse to resize
    95.     Image1.Move 0, 0
    96.     UserControl.Width = Image1.Width
    97.     UserControl.Height = Image1.Height
    98. End Sub
    99.  
    100. ' trap the parent form's Resize event
    101. ' this include the very first resize event
    102. ' that occurs soon after form's load
    103.  
    104. Private Sub ParentForm_Resize()
    105. If ParentForm.WindowState = 1 Then Exit Sub
    106.     If ParentWidth = 0 Then
    107.         Rebuild
    108.     Else
    109.         Refresh
    110.     End If
    111. End Sub
    112. ' save size and position of all controls on parent form
    113. ' you should manually invoke this method each time you add a new control
    114. ' to the form (through Load method of a control array)
    115. Sub Rebuild()
    116. ' rebuild the internal table
    117. Dim i As Integer, ctrl As Control
    118. ' this is necessary for controls that don't support
    119. ' all properties (e.g. Timer controls)
    120. On Error Resume Next
    121.  
    122. If Ambient.UserMode = False Then Exit Sub
    123. ' save a reference to the parent form, and its initial size
    124. Set ParentForm = UserControl.Parent
    125. ParentWidth = ParentForm.ScaleWidth
    126. ParentHeight = ParentForm.ScaleHeight
    127. ' read the position of all controls on the parent form
    128. ReDim Controls(ParentForm.Controls.Count - 1) As TControlInfo
    129. Dim Ctl As Control
    130. On Error Resume Next
    131. ' Put the code here to resize the controls
    132.  
    133. For i = 0 To ParentForm.Controls.Count - 1
    134.  
    135.     With Controls(i)
    136.  
    137.         '        Set .ctrl = ctrl
    138.  
    139.         If ParentForm.Controls(i).Left < -1000 Then  'For controls on diferent tab
    140.         Debug.Print ParentForm.Controls(i).Name
    141.             .Left = ParentForm.Controls(i).Left + 75000
    142.         Else
    143.             .Left = ParentForm.Controls(i).Left
    144.         End If
    145.  
    146.         .Top = ParentForm.Controls(i).Top
    147.         .Width = ParentForm.Controls(i).Width
    148.         .Height = ParentForm.Controls(i).Height
    149.         .FontSize = ParentForm.Controls(i).Font.Size
    150.  
    151.     End With
    152.  
    153. Next
    154.  
    155. End Sub
    156. ' update size and position of controls on parent form
    157. Sub Refresh()
    158. Dim i As Integer, ctrl As Control
    159. Dim widthFactor As Single, heightFactor As Single
    160. Dim minFactor As Single
    161. ' inhibits recursive calls if KeepRatio = True
    162. Static executing As Boolean
    163.  
    164. If executing Then Exit Sub
    165.  
    166. If Ambient.UserMode = False Then Exit Sub
    167.  
    168. If KeepRatio And ParentForm.WindowState = 0 Then
    169.     executing = True
    170.     ' we must keep original ratio
    171.     ParentForm.Height = HeightWidthRatio * ParentForm.Width
    172.     executing = False
    173. End If
    174.  
    175. ' this is necessary for controls that don't support
    176. ' all properties (e.g. Timer controls)
    177. On Error Resume Next
    178. widthFactor = ParentForm.ScaleWidth / ParentWidth
    179. heightFactor = ParentForm.ScaleHeight / ParentHeight
    180. ' take the lesser of the two
    181.  
    182. If widthFactor < heightFactor Then
    183.     minFactor = widthFactor
    184. Else
    185.     minFactor = heightFactor
    186. End If
    187.  
    188. Dim Ctl As Control
    189. LockWindow (ParentForm.hwnd)
    190. ' this is a regular resize
    191.  
    192. For i = 0 To ParentForm.Controls.Count - 1
    193.  
    194.     With Controls(i)
    195.  
    196.         ' the change of font must occur *before* the resizing
    197.         ' to account for companion scrollbar of listbox
    198.         ' and other similar controls
    199.  
    200.         If ResizeFont And (TypeOf ParentForm.Controls(i) Is TDBGrid) = False Then
    201.             ParentForm.Controls(i).Font.Size = .FontSize * minFactor
    202.         End If
    203.  
    204.         ' move and resize the controls - we can't use a Move
    205.         ' method because some controls do not support the change
    206.         ' of all the four properties (e.g. Height with comboboxes)
    207.  
    208.         If ParentForm.Controls(i).Left < -1000 Then
    209.         Debug.Print ParentForm.Controls(i).Name
    210.             ParentForm.Controls(i).Left = .Left * widthFactor
    211.             ParentForm.Controls(i).Left = ParentForm.Controls(i).Left - 75000
    212.         Else
    213.             ParentForm.Controls(i).Left = .Left * widthFactor
    214.         End If
    215.  
    216.         ParentForm.Controls(i).Top = .Top * heightFactor
    217.         ParentForm.Controls(i).Width = .Width * widthFactor
    218.  
    219.         If TypeOf ParentForm.Controls(i) Is ComboBox Then
    220.             lpara = ((.Height * heightFactor) \ Screen.TwipsPerPixelX) - 6
    221.             Call SendMessage(ParentForm.Controls(i).hwnd, CB_SETITEMHEIGHT, -1&, ByVal lpara)
    222.         Else
    223.             ParentForm.Controls(i).Height = .Height * heightFactor
    224.         End If
    225.  
    226.     End With
    227.  
    228. Next
    229.  
    230. UnlockWindow
    231. End Sub
    232.  
    233. 'Initialize Properties for User Control
    234. Private Sub UserControl_InitProperties()
    235. '    m_ResizeFont = m_def_ResizeFont
    236.     m_ResizeFont = m_def_ResizeFont
    237. End Sub
    238.  
    239. 'Write property values to storage
    240. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    241.     Call PropBag.WriteProperty("ResizeFont", m_ResizeFont, m_def_ResizeFont)
    242. End Sub
    243.  
    244. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    245. 'MemberInfo=0,0,0,1
    246. Public Property Get ResizeFont() As Boolean
    247.     ResizeFont = m_ResizeFont
    248. End Property
    249.  
    250. Public Property Let ResizeFont(ByVal New_ResizeFont As Boolean)
    251.     m_ResizeFont = New_ResizeFont
    252.     PropertyChanged "ResizeFont"
    253. End Property

  28. #68
    New Member
    Join Date
    Feb 2009
    Posts
    1

    Smile RE: Sent to Martin a question about Zoom fullscreen.

    Thanks Martin verry much.
    But with Sreadsheet which rows and column fixed wich a litte is not zoom full in spread.
    Only Spread zoom fullscreen. Rows and column not fixed in Spread zoom mode.

    Can you help me. Thanks very much.

    Soon hope you reply me answer.

  29. #69
    New Member
    Join Date
    Sep 2007
    Location
    Athens, Greece
    Posts
    11

    Re: Resizing form and textboxes ...

    Super Tool.
    Great, help me a lot.

    Very good tool.

  30. #70
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    362

    Re: Resizing form and textboxes ...

    Great tool MarkT fantastic job.

    i just have one question for the OCX control. im using a Main form that has a picturebox on it into which i load the "sub" forms at runtime. if i add the OCX control to the main form, how would i get the current visible "sub" form to also re-size?

    im using this method to load the "sub" form into the Main forms picturebox

    Code:
            UnloadForms
            Load frmRulesMain
            SetParent frmRulesMain.hwnd, picDock.hwnd
            frmRulesMain.Move 0, 0, 500, 1500
            frmRulesMain.Visible = True
    i have attempted to solve this issue by firstly creating a String called stActiveWindow in the Main Form, this string is populated by the "sub" forms Name property when it is loaded. then under the Main Forms resize event i had;

    Code:
    Private Sub Form_Resize()
        Dim frm As Form
        For Each frm In Forms
            If frm.Name = stActiveWindow Then
                frm.WindowState = 2
            End If
        Next
    End Sub
    in an attempt to try and make the "sub" form now maximise to the Main form. However this is not the case and the "sub" form stays at its normal size. Is anyone able to advise me of a solution to make the "sub" form resize at the same time as the Main form resize?

    additionally this only problem occurs to the current visible "sub" form, if i resize the Main form then open another "sub" form, the new "sub" form WILL maximise correctly. What im trying to achieve is when the Main form is resized the visible/loaded "sub" form resizes at the same time.

    Keep Smiling
    Last edited by aztrix; Aug 19th, 2010 at 06:16 AM.

  31. #71
    Junior Member
    Join Date
    Apr 2012
    Posts
    22

    Re: Resizing form and textboxes ...

    I know this is an old post but I just want to say thanks. I added this to my program and it works a treat

  32. #72
    Member
    Join Date
    May 2012
    Location
    La Plata, Buenos Aires, Argentina
    Posts
    52

    Re: Resizing form and textboxes ...

    I know it's a very old post, but since it's not marked as resolved, and last entry was 2012, and my question is usefull: here I go.
    I continued this post here: http://www.vbforums.com/showthread.p...65#post4568065
    saying (with attached images) that since MarkT OCX contrl works perfectly for adapting your form to a bigger screen, it has a problem adapting a form to a smaller screen, basically because VB6 itself resize the form to 'fit' the screen, and part of it is lost. (If you want, follow the link and comment there).

    Sorry for reopen an old post and thank you!

Page 2 of 2 FirstFirst 12

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