|
-
Apr 26th, 2009, 10:01 AM
#1
Thread Starter
Junior Member
[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:
Is how it looks using the classic theme
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.
-
Apr 26th, 2009, 10:39 AM
#2
Fanatic Member
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
-
Apr 26th, 2009, 01:10 PM
#3
Thread Starter
Junior Member
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.
-
Apr 26th, 2009, 01:54 PM
#4
Fanatic Member
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.
-
Apr 26th, 2009, 02:26 PM
#5
Thread Starter
Junior Member
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.
-
Apr 26th, 2009, 09:24 PM
#6
Fanatic Member
Re: Resizing forms and maintaining control ratio works differently on OS
 Originally Posted by Espyo
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
-
Apr 26th, 2009, 10:48 PM
#7
Re: Resizing forms and maintaining control ratio works differently on OS
 Originally Posted by Espyo
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.
-
May 2nd, 2009, 12:09 PM
#8
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|