|
-
Dec 15th, 2005, 05:09 PM
#1
Thread Starter
Giants World Champs!!!!
Control Resize Code
The following code will reposition and resize almost all controls on a form. Any comments and/or suggestions on improving this code will be greatly appreciated:
VB Code:
Option Explicit
Dim sngFrmTop As Single
Dim sngFrmLeft As Single
Dim sngFrmHeight As Single
Dim sngFrmWidth As Single
Dim sngCntTop() As Single
Dim sngCntLeft() As Single
Dim sngCntHeight() As Single
Dim sngCntWidth() As Single
Dim sngCntFont() As Single
Private Sub Form_Load()
Dim a As Long
On Error GoTo Form_Load_Error
sngFrmTop = Top
sngFrmLeft = Left
sngFrmHeight = Height
sngFrmWidth = Width
ReDim sngCntTop(Controls.Count)
ReDim sngCntLeft(Controls.Count)
ReDim sngCntHeight(Controls.Count)
ReDim sngCntWidth(Controls.Count)
ReDim sngCntFont(Controls.Count)
For a = 0 To Controls.Count - 1
With Me.Controls(a)
sngCntTop(a) = (.Top / sngFrmHeight)
sngCntLeft(a) = (.Left / sngFrmWidth)
sngCntHeight(a) = (.Height / sngFrmHeight)
sngCntWidth(a) = (.Width / sngFrmWidth)
sngCntFont(a) = (.FontSize / sngFrmHeight)
End With
Next a
On Error GoTo 0
Exit Sub
Form_Load_Error:
If Err.Number = 13 Then
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of Form Form1"
End If
End Sub
Private Sub Form_Resize()
Dim a As Long
On Error GoTo Form_Resize_Error
sngFrmTop = Top
sngFrmLeft = Left
sngFrmHeight = Height
sngFrmWidth = Width
For a = 0 To Me.Controls.Count - 1
With Me.Controls(a)
.Top = sngFrmHeight * sngCntTop(a)
.Left = sngFrmWidth * sngCntLeft(a)
.Height = sngFrmHeight * sngCntHeight(a)
.Width = sngFrmWidth * sngCntWidth(a)
.FontSize = Int(sngFrmHeight * sngCntFont(a))
End With
Next a
On Error GoTo 0
Exit Sub
Form_Resize_Error:
If Err.Number = 383 Then 'Catch Error for controls with read only properties
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Resize of Form Form1"
End If
End Sub
Last edited by Mark Gambo; Dec 15th, 2005 at 05:14 PM.
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."
-
Dec 16th, 2005, 08:23 AM
#2
Re: Control Resize Code
I like it a lot. I tried it with a form full of controls (practically everything in the standard toolbox) and it work like a charm.
My only suggestion would be that the variables declared at the Form level should be declared using Private. Dim really should be reserved for event level variables.
Having been a little anal and picky, I still like it and gave reps!
-
Dec 16th, 2005, 08:33 AM
#3
Banned
Re: Control Resize Code
well i am not quailified to comment on such hi fi code but its great and i will definetly use it in my project
-
Dec 16th, 2005, 10:07 AM
#4
Re: Control Resize Code
This works very nicely (I'm sure a link will be coming here from the FAQ soon!), I have a few comments for improvements in addition to Hacks tho -
- Form_Resize (and form_load) should ignore error 438 too ("Object doesn't support this property or method" - caused by the Shape control).
- Try this with a small form and maximize it, then restore it. You will see that text boxes are taller than they should be
It's an easy fix tho, just put the .FontSize line before the .Top line. - There is no need to resize controls if the form is minimized, so you could add this to the top of the Form_Resize event:
If Me.WindowState = vbMinimized Then Exit Sub - You should add comments to say "other code goes here", so people know where to put their own code
- ..and one (silly) picky one - you should rename sngCntFont to sngCntFontSize

-
Dec 16th, 2005, 01:26 PM
#5
Thread Starter
Giants World Champs!!!!
Re: Control Resize Code
Hack and Si,
Thanks for your suggestions and kind words , they will be implemented in Version 2. I have been doing some searching and I will probably wrap the code into a class. I was thinking about using a Private Type instead of the arrays that I am currently using similiar to Martin's code in this POST.
tux_newbie Thank You.
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."
-
Dec 16th, 2005, 01:38 PM
#6
Re: Control Resize Code
 Originally Posted by Mark Gambo
I have been doing some searching and I will probably wrap the code into a class.
If you do this, please make sure you give a good, clear, example of how to reference and use it from within a standard VB project.
There will be a lot of folks looking at this who will have no idea how to actually implement it if it is in a class without a good, working, example.
-
Dec 16th, 2005, 01:44 PM
#7
Thread Starter
Giants World Champs!!!!
Re: Control Resize Code
 Originally Posted by Hack
If you do this, please make sure you give a good, clear, example of how to reference and use it from within a standard VB project.
There will be a lot of folks looking at this who will have no idea how to actually implement it if it is in a class without a good, working, example.
Will do!
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."
-
Dec 16th, 2005, 08:44 PM
#8
Thread Starter
Giants World Champs!!!!
Re: Control Resize Code
Ok, here is version 2.0.0:
In a Class Module (Leave the name as Class1):
VB Code:
Option Explicit
Public a As Long
Public sngFrmTop As Single
Public sngFrmLeft As Single
Public sngFrmHeight As Single
Public sngFrmWidth As Single
Public Sub ControlResize(FormName As Form)
On Error GoTo ControlResize_Error
With FormName
If .WindowState = vbMinimized Then Exit Sub
sngFrmTop = .Top
sngFrmLeft = .Left
sngFrmHeight = .Height
sngFrmWidth = .Width
For a = 0 To .Controls.Count - 1
With .Controls(a)
.FontSize = Int(sngFrmHeight * ControlMetrix(a).sngCntFontSize)
.Top = sngFrmHeight * ControlMetrix(a).sngCntTop
.Left = sngFrmWidth * ControlMetrix(a).sngCntLeft
.Height = sngFrmHeight * ControlMetrix(a).sngCntHeight
.Width = sngFrmWidth * ControlMetrix(a).sngCntWidth
End With
Next a
End With
On Error GoTo 0
Exit Sub
ControlResize_Error:
If Err.Number = 383 Or Err.Number = 438 Or _
Err.Number = 380 Then
'Catch Error for controls with read only properties
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure ControlResize of Class Module Class1"
End If
End Sub
Public Sub GetFormMetrix(FormName As Form)
On Error GoTo GetFormMetrix_Error
With FormName
sngFrmTop = .Top
sngFrmLeft = .Left
sngFrmHeight = .Height
sngFrmWidth = .Width
ReDim ControlMetrix(.Controls.Count - 1)
For a = 0 To .Controls.Count - 1
With .Controls(a)
ControlMetrix(a).sngCntTop = (.Top / sngFrmHeight)
ControlMetrix(a).sngCntLeft = (.Left / sngFrmWidth)
ControlMetrix(a).sngCntHeight = (.Height / sngFrmHeight)
ControlMetrix(a).sngCntWidth = (.Width / sngFrmWidth)
ControlMetrix(a).sngCntFontSize = (.FontSize / sngFrmHeight)
End With
Next a
End With
On Error GoTo 0
Exit Sub
GetFormMetrix_Error:
If Err.Number = 13 Or Err.Number = 383 Or Err.Number = 438 Or _
Err.Number = 380 Then
'Catch Error for controls with read only properties
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure GetFormMetrix of Class Module Class1"
End If
End Sub
In a BAS Module:
VB Code:
Option Explicit
Public Type ControlMetrix
sngCntTop As Single
sngCntLeft As Single
sngCntHeight As Single
sngCntWidth As Single
sngCntFontSize As Single
End Type
Public ControlMetrix() As ControlMetrix
and in the Form copy the following code and
place some controls in various positions on the form:
VB Code:
Option Explicit
Private FormResize As Class1
Private Sub Form_Load()
Set FormResize = New Class1
Call FormResize.GetFormMetrix(Me)
End Sub
Private Sub Form_Resize()
Call FormResize.ControlResize(Me)
End Sub
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."
-
Dec 16th, 2005, 09:45 PM
#9
Re: Control Resize Code
Even pickier: Metrix is spelled Metrics. 
Haven't tried it yet, but will do soon.
-
Dec 17th, 2005, 06:30 AM
#10
Thread Starter
Giants World Champs!!!!
Re: Control Resize Code
 Originally Posted by dglienna
Even pickier: Metrix is spelled Metrics.
Haven't tried it yet, but will do soon.
I know that, "FormMetrix" is my brand name . So that when I see this code posted to the board by someone else, I know where they got it .
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."
-
Sep 29th, 2007, 12:55 PM
#11
Frenzied Member
Re: Control Resize Code
Hi Mark, thanks very much for this code and your work too 
I am trying to impliment this into my project.
I have an MDI form and numerous child forms
I have copied your code exactly into a test project with one MDI form and one child form.
On the child form I have the following:
Command button
Text box
Listbox
Combo box
Picture box with picture
Label
Dir box
In a frame I have:
command button
combo box
text box
listbox
When I run this I get the error:
Runtime error 383 'Height' property is read only
I see you have this in the error handler, but for some reason it is not getting that far. It doesn't error out straight away - 'a' = 6.
The project stops on the line
Code:
Public Sub ControlResize(FormName As Form)
On Error GoTo ControlResize_Error
With FormName
If .WindowState = vbMinimized Then Exit Sub
sngFrmTop = .Top
sngFrmLeft = .Left
sngFrmHeight = .Height
sngFrmWidth = .Width
For a = 0 To .Controls.Count - 1
With .Controls(a)
.FontSize = Int(sngFrmHeight * ControlMetrix(a).sngCntFontSize)
.Top = sngFrmHeight * ControlMetrix(a).sngCntTop
.Left = sngFrmWidth * ControlMetrix(a).sngCntLeft
.Height = sngFrmHeight * ControlMetrix(a).sngCntHeight
Any idea what I am doing wrong?
Does this handle Flexgrids and Listviews?
Last edited by aikidokid; Sep 29th, 2007 at 01:00 PM.
Reason: add value of counter for controls
-
Sep 30th, 2007, 11:06 AM
#12
Re: Control Resize Code
It will get an error like that if the control doesn't support setting the value (some controls are fixed height/width).
The error handler should cope with it, so I guess you just have the IDE's break option set incorrectly. Right-click in a code window, and select "Toggle", and select either "Break in Class Module" or "Break on Unhandled Errors".
-
Sep 30th, 2007, 11:37 AM
#13
Frenzied Member
Re: Control Resize Code
Thanks si_the_geek, that sorted it. 
How does resizing work with MDI forms?
Do you have to put something in the form_activate of the child form to say, if I am active and MDI form changes size, resize me?
If this is along the right lines, how about when I open another child form after the MDI form has been resized?
-
Sep 30th, 2007, 11:48 AM
#14
Re: Control Resize Code
You don't need to do anything in the _activate events.
If the MDI child forms are maximised, they will be resized (and so their own resize events will fire) when the MDI parent is resized.
If the MDI child forms are not maximised, they will stay the same size when the parent is resized (and scrollbars will be shown in the parent if apt). If you want to change that behaviour, you will need to write code in the Resize event of the parent.
All non-minimised MDI child forms have the same windowstate (you can't have a mixture of 'maximised' and 'normal'), so if one is maximised they all will be. If you open a new child (without specifying a windowstate) it will be shown either maximised or normal, matching the windowstate of the existing forms.
-
Sep 30th, 2007, 12:08 PM
#15
Frenzied Member
Re: Control Resize Code
 Originally Posted by si_the_geek
If the MDI child forms are maximised, they will be resized (and so their own resize events will fire) when the MDI parent is resized.
Now you say it, it makes sense
 Originally Posted by si_the_geek
All non-minimised MDI child forms have the same windowstate (you can't have a mixture of 'maximised' and 'normal'), so if one is maximised they all will be. If you open a new child (without specifying a windowstate) it will be shown either maximised or normal, matching the windowstate of the existing forms.
Ok, just looked at this and I understand, so, why when I open the MDI form, I have one of my childforms open with it, but it only shows when the windowstate is either normal or minmised. If it is maximised it doesn't show.
I can then open other childforms and they are maximised!
-
Sep 30th, 2007, 12:15 PM
#16
Re: Control Resize Code
That doesn't sound right.. I'd assume that you have code somewhere that is changing the state/position etc, but don't know quite what is going on. It is also possible that your child form isn't actually a child (check the properties window).
I'd recommend debugging it.. step thru and check the windowstate/position/etc at each stage.
-
Sep 30th, 2007, 01:10 PM
#17
Frenzied Member
Re: Control Resize Code
 Originally Posted by si_the_geek
I'd assume that you have code somewhere that is changing the state/position etc, but don't know quite what is going on. It is also possible that your child form isn't actually a child (check the properties window).
I'd recommend debugging it.. step thru and check the windowstate/position/etc at each stage.
Firstly, check it and it is a child form.
What do you mean by:
you have code somewhere that is changing the state/position etc
I thought that if the childform was set to maximised, then the form should resize with the MDI form, or does the childform still have to call it's own resize code, as in the MDI resize event?
I know how to debug, or I thought I did, but how do I debug the windowstate?
-
Sep 30th, 2007, 01:16 PM
#18
Frenzied Member
Re: Control Resize Code
Hmm, that's interesting, I have solved the probelm by changing the form borderstyle to 2. It doesn't seem to want to play with a borderless childform
Not really want I wanted to do!
Last edited by aikidokid; Sep 30th, 2007 at 01:24 PM.
-
Sep 30th, 2007, 02:09 PM
#19
Re: Control Resize Code
I don't use borderless forms, but I just tried it and got the same.. not sure what is going on there!
 Originally Posted by aikidokid
What do you mean by:
you have code somewhere that is changing the state/position etc
I thought perhaps you had code somewhere (perhaps in a resize event) that was changing the windowstate etc.
I thought that if the childform was set to maximised, then the form should resize with the MDI form,
Correct.
or does the childform still have to call it's own resize code, as in the MDI resize event?
The child form would never need to call it's own resize event - it would be called automatically when the form resizes.
Depending on the program, you may want to resize the child form (which would automatically fire its resize event) from the MDI parent.
I know how to debug, or I thought I did, but how do I debug the windowstate?
Add formX.windowstate as a Watch (making sure Procedure is 'all', and preferably the same for Module), and then use breakpoints and/or step the code.
-
Oct 1st, 2007, 09:56 AM
#20
Frenzied Member
Re: Control Resize Code
Sorry to be a bit dim here.
I have tried to work this out, mainly by trial and error.
If I have the following code in place in the ChildForm.
Code:
Option Explicit
Private FormResize As Class1
Private Sub Form_Load()
Set FormResize = New Class1
Call FormResize.GetFormMetrix(Me)
End Sub
Private Sub Form_Resize()
Call FormResize.ControlResize(Me)
End Sub
All ChildForm properties are:
Windowstate = maximised
Borderstyle = 2
Controlbox = False
I can get the form to load maximised, but when I try to minimise the form or select the 'Restore Down' button the MDI form changes but the ChildForm stays the same.
Also I am getting a subscript error sometimes.
Could this be because I have this code in all of the childforms (17) and it's still get the previous number of controls in memory?
I wouldn't have thought so, but .....
Also, when I change resolution from 1280X1024 to 1024X768 the forms stay the same size as they were for the higher resolution!
I am totally confused now. This is why (originally) I made the form a fixed size without letting the user resize it! (not a good idea I know )
Last edited by aikidokid; Oct 1st, 2007 at 10:01 AM.
-
Oct 1st, 2007, 10:50 AM
#21
Re: Control Resize Code
Each form has their own instance of the class, so they wont get each others values. I don't know where the subscript error is coming from (but then I haven't looked at the class yet).
If you resize the MDI Parent, the child forms will only resize if they are maximised. If their WindowState is Normal, they will stay the same size (and the parent will get scrollbars if apt); if you want to change that, you will need to add code to the resize event of the parent (check if Me.ActiveForm.WindowState is Normal, if it is then resize the child forms as you want).
-
Oct 1st, 2007, 10:59 AM
#22
Frenzied Member
-
Oct 1st, 2007, 11:25 AM
#23
Re: Control Resize Code
I think the issue is that the size of 'maximised' varies, and as such the positions of controls may not be appropriate.
Change the Child form properties, so that their initial Windowstate is Normal (and controls arranged appropriately). That will allow the code in Form_Load to store the relative (design-time) positions appropriately, and any subsequent resizing should work properly.
If you want the child forms to be maximised when they are shown, you can change the windowstate at the end of form_load (but this will apply every time they open).
-
Oct 1st, 2007, 11:41 AM
#24
Frenzied Member
Re: Control Resize Code
 Originally Posted by si_the_geek
I think the issue is that the size of 'maximised' varies, and as such the positions of controls may not be appropriate.
Change the Child form properties, so that their initial Windowstate is Normal (and controls arranged appropriately). That will allow the code in Form_Load to store the relative (design-time) positions appropriately, and any subsequent resizing should work properly.
If you want the child forms to be maximised when they are shown, you can change the windowstate at the end of form_load (but this will apply every time they open).
I have changed the windowstate to Normal and added the line:
Me.Windowstate = 2
to the Form_load and to the Form_Activate, as more than one childform could be open at any time.
I still get the complete form in the upper left of the screen.
The startupposition = 0 'Manual' as this is all it will let me have.
Also, in my formload I have;
Me.Top = 0
Me.Left = 0
But even taking this out, it's still the same.
Is this anything to do with the design of my form, as it looks centered at the 1024 x 768 resolution?
Last edited by aikidokid; Oct 1st, 2007 at 11:47 AM.
-
Oct 1st, 2007, 11:54 AM
#25
Re: Control Resize Code
To be honest, I think I need to see the project to get my head around it clearly.
-
Oct 1st, 2007, 11:57 AM
#26
Frenzied Member
Re: Control Resize Code
 Originally Posted by si_the_geek
To be honest, I think I need to see the project to get my head around it clearly.
Do you mind if I email it to you?
-
Oct 1st, 2007, 12:47 PM
#27
-
Oct 1st, 2007, 02:01 PM
#28
Re: Control Resize Code
I design forms in whatever resolution I am using - the resize code is what really matters (but if there are lots of controls, I try to make sure they fit in 800x600, as that is the minimum resolution users should have). I personally write resize code each time (and only move controls, not size them) rather than using something generic like this.. but once the issues are solved, this generic method should be fine.
After a little play I can see that the declaration of the ControlMetrix() array should actually be in the class (as Private) rather than the module - as it is specific to each form (and thus class instance). The variables that are already within the class should also be Private.
Ideally the code in the class would refer to .ScaleWidth/.ScaleHeight rather than .Width/.Height, so that the title bar and borders do not have an effect. Also, as the scalemode may change (and the controls are measured in the scalemode), you should use ScaleX/ScaleY to ensure they are in a constant scale, eg:
Code:
sngFrmHeight = .ScaleY(.ScaleHeight, .ScaleMode, vbTwips)
sngFrmWidth = .ScaleX(.ScaleWidth, .ScaleMode, vbTwips)
(this should be changed in both subs in the class).
In my testing the controls were in almost the correct position, just a little larger than they should be (so "Notes" was half off-screen, and the buttons were right off).
One problem I found is that your controls are on a frame.. which is a control, and as such will also be resized itself, and affect the position of the controls that are on it. By removing the frame, the display was more accurate (but still not quite right). Alternatively, the code in the class could be modified to deal with parent objects (like frames and pictureboxes), but that would take a fair amount of effort.
Another issue is that the statusbar seems to actually hide part of the form, rather than limiting the size as would be expected. Unfortunately I cannot see a way to correct the effect that has on this code (as the MDI parent scaleheight etc act as if it isn't there).
I don't think this will solve your issues completely, but hopefully things will be improved.
-
Oct 1st, 2007, 02:22 PM
#29
Frenzied Member
-
Oct 2nd, 2007, 08:01 AM
#30
Frenzied Member
Re: Control Resize Code
 Originally Posted by si_the_geek
I design forms in whatever resolution I am using - the resize code is what really matters (but if there are lots of controls, I try to make sure they fit in 800x600, as that is the minimum resolution users should have).
OK, got that, and I assume that the screen size would make no difference.
I have a 19" monitor, and a friend testing this has a 15" monitor.
 Originally Posted by si_the_geek
I personally write resize code each time (and only move controls, not size them)
Would this be ok for such a difference in screen resloution (1024 x 768 - 1280 x 1024)
Althought that said, the resolution is down to the user - and their eye sight!
 Originally Posted by si_the_geek
After a little play I can see that the declaration of the ControlMetrix() array should actually be in the class (as Private) rather than the module - as it is specific to each form (and thus class instance). The variables that are already within the class should also be Private.
Done.
 Originally Posted by si_the_geek
Ideally the code in the class would refer to .ScaleWidth/.ScaleHeight rather than .Width/.Height, so that the title bar and borders do not have an effect. Also, as the scalemode may change (and the controls are measured in the scalemode), you should use ScaleX/ScaleY to ensure they are in a constant scale, eg:
Code:
sngFrmHeight = .ScaleY(.ScaleHeight, .ScaleMode, vbTwips)
sngFrmWidth = .ScaleX(.ScaleWidth, .ScaleMode, vbTwips)
(this should be changed in both subs in the class).
Done.
 Originally Posted by si_the_geek
In my testing the controls were in almost the correct position, just a little larger than they should be (so "Notes" was half off-screen, and the buttons were right off).
I didn't get this!
At 1024 x 768 it looked as it does in the IDE.
 Originally Posted by si_the_geek
One problem I found is that your controls are on a frame.. which is a control, and as such will also be resized itself, and affect the position of the controls that are on it. By removing the frame, the display was more accurate (but still not quite right).
Removed this frame.
 Originally Posted by si_the_geek
Another issue is that the statusbar seems to actually hide part of the form, rather than limiting the size as would be expected. Unfortunately I cannot see a way to correct the effect that has on this code (as the MDI parent scaleheight etc act as if it isn't there).
The status bar is not essential, but I would prefer to have it.
I suppose one option would be to add it to all forms
 Originally Posted by si_the_geek
I don't think this will solve your issues completely, but hopefully things will be improved.
To be honest, I don't seem to have this any further forward than before.
It looks ok at the lower of the two resolutions, but anything else just doesn't look correct!
I tried to comment out the resizing of the size of the controls, just leaving the top and left to be altered, but as I said, the complete form still sits in the top left hand of the MDI form, when at a higher resolution.
Did you alter any of the code on the actual form?
I am beginning to wonder if I should just design the forms for the lower of these resolutions and disable the Resize as I had it before.
Your comment on any of this please si_the_geek!
-
Oct 2nd, 2007, 01:42 PM
#31
Re: Control Resize Code
 Originally Posted by aikidokid
OK, got that, and I assume that the screen size would make no difference.
I have a 19" monitor, and a friend testing this has a 15" monitor.
Correct, the size of the monitor is irrelevant - only the resolution (and various components of it, such as "large fonts") matters.
Would this be ok for such a difference in screen resloution (1024 x 768 - 1280 x 1024)
Althought that said, the resolution is down to the user - and their eye sight!
Standard Windows dialogs are not resized (unless using Large Fonts etc), so if the user can't see them then they have bigger issues than just your program!
The status bar is not essential, but I would prefer to have it.
I suppose one option would be to add it to all forms
True, but that would take a lot of effort.
Did you alter any of the code on the actual form?
Not really (only enough to stop errors from code which used other forms/modules).
I didn't get this!
At 1024 x 768 it looked as it does in the IDE.
Well to be honest I had only have solved the potential issues with ScaleMode... you should also convert all values for Top/Height using ScaleY and all values of Left/Width using ScaleX, eg:
Code:
.Top = ScaleY(sngFrmHeight * ControlMetrix(a).sngCntTop, vbTwips, .ScaleMode)
Code:
ControlMetrix(a).sngCntTop = ScaleY(.Top / sngFrmHeight, .ScaleMode, vbTwips)
I am beginning to wonder if I should just design the forms for the lower of these resolutions and disable the Resize as I had it before.
That is roughly the way I do it, I never bother with changing font sizes, or expanding controls in terms of percentage... the only time I resize/move controls is when there is a control which has scrollbars (such as a FlexGrid or ListView) to expand into the space, and then simply have code like: FG.Height = Me.ScaleHeight - FG.Top - MyBorderSize
To deal with resolution options like Large Fonts, I tend to re-position controls based on their run-time size (in form_initialise). In your form, I would set all labels to Autosize, then (if needed) increase the .Left of the first 'column' of textboxes to allow for their width, then the same for the second column etc, and similar for the 'rows'.
-
Oct 5th, 2007, 01:12 PM
#32
Frenzied Member
Re: Control Resize Code
ok, been working on this fro 3 days now
I have it pretty much sorted I think.
Just a couple of problems to overcome:
1, When the MDI loads, in the FormLoad event it opens a ChildForm. This has, as suggested above, in the Form_Load and in the Form_Activate (not sure if I needed it here as well)
Now when the MDI form and the first ChildForm are opened, and I then click on the Maximise button for the MDI form, the first ChildForm is maximised.
When the next ChildForm is opened it is not maximised?
If I maximize the MDI after I open another ChildForm it works.
Not sure what I am missing here!
2, How to resize the columns of a Flexgrid and a Listview.
Where would this go, in the childform resize, or in the control resize event?
Last edited by aikidokid; Oct 7th, 2007 at 05:31 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|