Results 1 to 8 of 8

Thread: [RESOLVED] Resizing forms and maintaining control ratio works differently on OS

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    24

    Resolved [RESOLVED] Resizing forms and maintaining control ratio works differently on OS

    When the user resizes the form, I want to make the controls increase in size and anchor in proportion with the form's width and height. Well, everything is ok with my code, except that my system's style is set to the classic Windows theme, and when I try on another style (the one most users have), it looks horrible.
    For instance, in mine, the main textbox control is at the same distance from the form's width as it is from the form's left (120 twips from the form's left and the control's left, and 120 twips from the control's width to the form's width).
    When I use the other theme, it's still at 120 distance from the lefts, but the control's right is exactly in the same place as the form's right.
    In image format:
    Name:  1.gif
Views: 345
Size:  937 Bytes Is how it looks using the classic theme
    Name:  2.gif
Views: 368
Size:  926 Bytes Is how it looks using the common theme

    So, I'm looking for a solution to make the resizing work well in every computer. Specially if the solution is about an optimized resizing algorithm.

  2. #2
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Resizing forms and maintaining control ratio works differently on OS

    this is how I do it. doesn't work with certain controls like comboboxes though it does work with listboxes.
    Code:
    Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Dim WinBox As RECT, Ready As Boolean
    Private Sub Form_Load()
    Me.Show
    DoEvents
    GetClientRect Me.hwnd, WinBox
    Ready = True
    End Sub
    
    Private Sub Form_Resize()
    Dim c As Object
    Dim NewBox As RECT
    If Not Ready Then Exit Sub
    GetClientRect Me.hwnd, NewBox
    On Error Resume Next
    For Each c In Me.Controls
        Debug.Print c.Name
        c.Move c.Left * NewBox.Right / WinBox.Right, _
                c.Top * NewBox.Bottom / WinBox.Bottom, _
                c.Width * NewBox.Right / WinBox.Right, _
                c.Height * NewBox.Bottom / WinBox.Bottom
    Next
    WinBox = NewBox
    End Sub
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    24

    Re: Resizing forms and maintaining control ratio works differently on OS

    Thanks, but that didn't seem to work to well. Not to mention that it looks more complex than what it needs to be... :S
    Either way, I figured that it's best to merely give the coordinates to be in the best aspect for the recent theme. Those who use the classic theme, won't see the control's stretched out next to the form's extents, but its best. Besides, this needs to be finished in some months, and I can't spend to much time on it. Thanks anyway.

  4. #4
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Resizing forms and maintaining control ratio works differently on OS

    Complex????? That's all there is to it, no more code to add.

    Sorry it didn't work for you but maybe it will work for someone else.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    24

    Re: Resizing forms and maintaining control ratio works differently on OS

    That wasn't exactly what I meant to say. Complex from my game's point of view, in which I use 3 API calls. But, seriously, it is really simple. Too bad it didn't work.

  6. #6
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Resizing forms and maintaining control ratio works differently on OS

    Quote Originally Posted by Espyo View Post
    Too bad it didn't work.
    Do you mean it didn't work at all or for your application- because if it didnt work at all then the baseline wasn't set in Form_Load after the show command.

    Code:
    Private Sub Form_Load()
    Me.Show
    DoEvents
    GetClientRect Me.hwnd, WinBox
    Ready = True
    End Sub
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Resizing forms and maintaining control ratio works differently on OS

    Quote Originally Posted by Espyo View Post
    So, I'm looking for a solution to make the resizing work well in every computer.
    I'd bet a dollar you were using Form.Width, Form.Height, etc... in your calculations. Doing so with always leave your resized controls a little off because window borders (and caption bar) aren't always the same size. In fact, you have to assume they will be different on every machine.

    Instead, use Form.ScaleWidth and Form.ScaleHeight. These give the dimensions of the usable area, which ignores window borders and the caption bar. The usable area is always the same on any machine.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    24

    Re: Resizing forms and maintaining control ratio works differently on OS

    Bingo, Ellis Dee. I was using Form.Width and Form.Height. I did try to pay attention to ScaleHeight and Width, but I figured that it wasn't nothing to important. Although one of the controls (a TextBox) didn't want to work with the same measures as the others... But it worked well nonetheless.

    And technorobbo, I only needed it on one form, if that's what you mean. It didn't work as in it was still awkward on other themes. But that's ok now. Thanks for your time, guys.

Tags for this Thread

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