Resize Form controls to Fit different Screen Resolutions Automatically-VBForums
Results 1 to 14 of 14

Thread: Resize Form controls to Fit different Screen Resolutions Automatically

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Resize Form controls to Fit different Screen Resolutions Automatically

    Guys, I have designed my application on a machine with a 800 x 600 resolution. However, when I try running it on a machine with a 1024 x 768 specifications, I end up with a lot of empty space and doe not look appealing. How can I ensure that when I move to a machine with a higher resolution, my controls get resized automatically? I will really appreciate getting a code that can help me out.

    Thanks

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Try searching, I've seen the same question before.

    Here is one way, i can't find the thread tho

    http://www.vbforums.com/showpost.php...79&postcount=3

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    You will have to use Form_Resize event to place your controls correctly:

    VB Code:
    1. Private Sub Form_Resize()
    2.     myControl.Move '...
    3. End Sub

  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Quote Originally Posted by osemollie
    Guys, I have designed my application on a machine with a 800 x 600 resolution. However, when I try running it on a machine with a 1024 x 768 specifications, I end up with a lot of empty space and doe not look appealing. How can I ensure that when I move to a machine with a higher resolution, my controls get resized automatically? I will really appreciate getting a code that can help me out.

    Thanks
    Check Here Also
    Check Out The zip file
    Last edited by shakti5385; Sep 4th, 2006 at 05:31 AM.

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,171

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    There are resize ocx's you can buy. But here is just a simple example of resizing.
    Attached Files Attached Files
    Keith

    I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.


  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    VB Code:
    1. Private Type ControlPlaces
    2.     Contrl As Control
    3.     Left As Single
    4.     Top As Single
    5.     Width As Single
    6.     Height As Single
    7. End Type
    8. Dim CtrlPos() As ControlPlaces
    9.  
    10. Private Sub Form_Load()
    11.     ReloadPos
    12. End Sub
    13. Sub ReloadPos()
    14.     ReDim CtrlPos(Me.Controls.Count)
    15.     Dim Ctrl As Control
    16.     Dim Num As Long
    17.    
    18.    
    19.         For Each Ctrl In Me.Controls
    20.             Set CtrlPos(Num).Contrl = Ctrl
    21.             CtrlPos(Num).Left = Ctrl.Left
    22.             CtrlPos(Num).Top = Ctrl.Top
    23.             CtrlPos(Num).Width = Ctrl.Width
    24.             CtrlPos(Num).Height = Ctrl.Height
    25.             Num = Num + 1
    26.         Next
    27.        
    28.     CtrlPos(UBound(CtrlPos)).Left = Me.Left
    29.     CtrlPos(UBound(CtrlPos)).Top = Me.Top
    30.     CtrlPos(UBound(CtrlPos)).Width = Me.Width
    31.     CtrlPos(UBound(CtrlPos)).Height = Me.Height
    32. End Sub
    33.  
    34.  
    35. Private Sub Form_Resize()
    36.     WChng = Me.Width / CtrlPos(UBound(CtrlPos)).Width
    37.     HChng = Me.Height / CtrlPos(UBound(CtrlPos)).Height
    38.    
    39. For x = 0 To UBound(CtrlPos) - 1
    40.     CtrlPos(x).Contrl.Left = CtrlPos(x).Left * WChng
    41.     CtrlPos(x).Contrl.Top = CtrlPos(x).Top * HChng
    42.     CtrlPos(x).Contrl.Width = CtrlPos(x).Width * WChng
    43.     CtrlPos(x).Contrl.Height = CtrlPos(x).Height * HChng
    44. Next
    45. End Sub

    I have checked out the above code as suggested, but when I try running the application, I get an error telling me "Object required" I honestly have no idea what is required.

    Help me out if you can.

  7. #7
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    check the post 4 and download a zip file from there!

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,171

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Quote Originally Posted by osemollie
    [Highlight=VB]
    I have checked out the above code as suggested, but when I try running the application, I get an error telling me "Object required" I honestly have no idea what is required.
    Well it works perfectly on my machine with no errors. If it did have errors I wouldn't have posted it.

    Which line does it say Object Required?
    Keith

    I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.


  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Quote Originally Posted by Keithuk
    Well it works perfectly on my machine with no errors. If it did have errors I wouldn't have posted it.

    Which line does it say Object Required?
    Keithuk, no offense meant. I just wanted to inform the forum members that my code had raised an error.

    The error is first encountered below:
    VB Code:
    1. For Each Ctrl In Me.Controls
    2.             Set CtrlPos(Num).Contrl = Ctrl
    3.             CtrlPos(Num).Left = Ctrl.Left
    4.             CtrlPos(Num).Top = Ctrl.Top
    5.             CtrlPos(Num).Width = Ctrl.Width
    6.             CtrlPos(Num).Height = Ctrl.Height
    7.             Num = Num + 1
    8.         Next

  10. #10
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    On what line does it occur?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Quote Originally Posted by Hack
    On what line does it occur?
    VB Code:
    1. Set CtrlPos(Num).Contrl = Ctrl

  12. #12
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    If you comment out that line, does it work?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Quote Originally Posted by Hack
    If you comment out that line, does it work?
    No, it highlights the next line and so on ...

  14. #14
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Resize Form controls to Fit different Screen Resolutions Automatically

    Make sure u include the declarations
    VB Code:
    1. Private Type ControlPlaces
    2.     Contrl As Control
    3.     Left As Single
    4.     Top As Single
    5.     Width As Single
    6.     Height As Single
    7. End Type
    8. Dim CtrlPos() As ControlPlaces

    Also a zip file with the code

    If you still experience problems then i might have missed something
    Last edited by Andrew G; Sep 6th, 2006 at 06:28 AM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.