Can someone tell me how to get the text box to resize along with the form? I also have 2 command buttons under the text box which I want to stay centered and at the bottom of the form when I resize it.
Right now, the textbox stays the same size when I resize the Main Form and the command buttons stay in the same place directly under the textbox.
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
Sub ResizeControls()
On Error Resume Next
Dim I As Integer
For I = 0 To Controls.Count - 1
With ProportionsArray(I)
' move and resizecontrolsControls(I).Move .LeftProportions * ScaleWidth, _
.TopProportions * ScaleHeight, _
.WidthProportions * ScaleWidth, _
.HeightProportions * ScaleHeight
End With
Next I
End Sub
'Form initialize event
Private Sub Form_Initialize()
InitResizeArray
End Sub
'Form resize event
Sub Form_Resize()
ResizeControls
End Sub
If you want controls on your form to resize along with the form you'll need to add some code to accomplish this in the Form_Resize event. In your case you could determine the size of the textboxes in proportion to the dimensions of the form and center the command buttons based on their width(s) and the width of the form.
I'd like to take credit for the code, but I can't. All I did was to correct a couple of mistakes in a piece of code I found in this forum a couple of years ago. Here is the originallink
I'm looking at your code here and it appears that the problem you are having with the combo boxes not resizing is quite simple. The height property of a combo box is read only. If you try to use the move method on a combo box it will cause an error. Since you have resume next, it will just skip that control. Something like this might be better.
Thanks for the reply, but I knew the reason for the problem and I was just alerting people to it. My On Error Resume Next code, while avoiding an error when the combobox is encountered was actually put there for menu items etc. that don't have a Move method. BTW, what do you see as the advantage of your code over mine?
I was able to put it to use in one of my projects and added a couple of simple mods to it that I thought others might find use for.
I wrapped it up into a class and added another method to be able to specify whether or not you want a particular control (or controls) to move or resize.
Hope this is of use to someone...
Here's the class module code:
VB Code:
Option Explicit
Private Type CtrlProportions
Name As String
Move As Boolean
Resize As Boolean
HeightProportions As Single
WidthProportions As Single
TopProportions As Single
LeftProportions As Single
End Type
Private mProportionsArray() As CtrlProportions
Public Sub InitResizeArray(objForm As Form)
Dim I As Integer
On Error Resume Next
ReDim mProportionsArray(0 To objForm.Controls.Count - 1)
Mike, please don't post your responses in this thread because people won't know what you are referring to. I created a new Resizing Controls thread with your other comments.
Ok, will do. The thing is I use dozens of controls and potentially two or three hundred on the same form depending how the user configures his form. I realise this is puting a great burden on the system.
Would you have a suggestion as to a why to the SSTab issue. I will adapt your code and see what comes out. Thanks.
Please Martin, if you have a second can you look at the screenshots for my app using your resize code. As you can see, what i did was to maximise then minimise the window. We see that on tab one all three lines of controls appear correctly but then on tab 3 the same three lines appear when they really belong to tab 3. also on the last shot the frames are all wrong. Any ideas as to why this is and how to remedy it? Thanks again.
Originally posted by MikeGarvin Ok. Thanks. I got the tab #'s wrong, it should read:
We see that on tab one all three lines of controls appear correctly but then on tab 3 the same three lines appear when they really belong to tab 1.
How did you create those controls that you want to be on tab 3? Did you draw (or copy/paste) them on that tab, or did you just double-click the control in the toolbar? The latter doesn't work properly for a container control like the tabbed dialog. To see if that is your problem do something like this:
MsgBox MyControlThatsOnATab.Container.Tab
and see what tab it's actually on. If that shows you have a problem then do the following if you want the control on tab 3.
Thanks Martin. The controls are created at run time from the first line, which is there at design time. I simply create new lines of controls from what the user chooses.
I will try what you suggest. Thanks.
Would you know why the frames don't appear on the other sstabs. I believe they are there but are offset to the left completely as explained in my initial post. Cheers.
The flickering was not very nice before but now with 6*24 frames on my app it's just bad . I find it incredible the left property on tabs should not just stay to a the value you assign it at design time. VB, eh, some language!
Originally posted by MartinLiss Does that resolve your problem?
Sorry to re-open this thread...but whats the final code here?
Should this just be added to a public module and called in any resize event of any form? Also I read in someone's response that this does not work when someone hits the maximize button. Is this true?
Yes that all you need to do and if you call it from the form's resize event it will work fine when you maximize the form. In my app I found that I need to do the following when the form is minimized however.
VB Code:
On Error Resume Next ' Needed if the form is minimized
Is it me..or does this code totally not work for tabbed pane layout ? The controls on all other tabs disappear. The flex grids disappear. The combo boxes dont resize.
Comboboxes do resize, there's a post in the thread that talks about it. Unfortunately I think I remember someone else saying that Tabs don't work right, sorry about that.
From: Microsoft Knowledge Base Article - 187562
"HOWTO: Resize the Controls in SSTab When Form is Resized"
When a form is resized, the controls present in the form can be resized to fit into the form by using the Move method. However, it is not straightforward to resize the controls present inside an SSTab control because the Left property values of controls present in the inactive tabs are less than 0. This article describes a way to resize the controls present in an SSTab control.
The SSTab control hides the controls present in the inactive tabs by setting their Left property values less by 75000. Hence, changing the Left property of a control on an inactive tab in the form's resize event may cause that control to stop showing in a particular tab.
=======================================
I made some Rube Goldberg changes to Achichincle's class above, see "SSTab" in code:
VB Code:
'To use, put the dozen or so lines below inside your form:
Public Sub SetControlProperties(strName As String, flgMove As Boolean, flgResize As Boolean)
Dim I As Integer
For I = 0 To UBound(mProportionsArray())
If mProportionsArray(I).Name = strName Then
mProportionsArray(I).Move = flgMove
mProportionsArray(I).Resize = flgResize
End If
Next I
End Sub
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
I think Achichincle's class scheme has the advantage of working with multiple forms, i.e. they'll each have their own instance and won't interfere.
I was wondering how this would handle dynamically created controls at run-time ...
By just adding a call to
VB Code:
mobjResizer.InitResizeArray Me
after creating them it all seems to work beautifully.
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15