|
-
Apr 1st, 2000, 04:56 AM
#1
Thread Starter
Member
I've seen some apps do this but I'm not sure how to do it w/ VB. When my form resizes how can I make a text box resize also? Thanks in advance.
-
Apr 1st, 2000, 06:17 AM
#2
Addicted Member
This might help...
Private Sub Form_Resize()
Text1.Height = Form1.Height / 2
Text1.Width = Form1.Width / 2
Refresh
End Sub
You may have to play around with the initial position of
the text box, to achieve your objective
GRAHAM
-
Apr 1st, 2000, 07:04 AM
#3
Frenzied Member
I don't know where graham pulled those text1.width=form.Width/2 from, or maybe it was just an arbitrary example.
The Form resize event is fired whenever the user, or another piece of code changes the size of your form.
to change the position of your textbox change it's width height, top and left properties. Work out a formula for where you want the top, left corner of your textbox and what you want the width and height to be. For example to set the text box in the centre of your form, so it's the same dimensions as your form but one third of the width and heightuse this code
Code:
Private Sub Form_Resize()
'Set width and height properties to
'1 third of the forms dimensions
Text1.Width = Form1.Width / 3
Text1.Height = Form1.Height / 3
'You can now get the new dimensions of the textbox
'by reading them off the properties
'calculate the new position of the textbox
'the formulae are quite easy to prove
Text1.Left = 0.5 * (Form1.Width - Text1.width)
Text1.Top = 0.5* (Form1.Height - Text1.Height)
End Sub
-
Apr 2nd, 2000, 11:30 PM
#4
Thread Starter
Member
The application that I'm talking about is Fix-It Utilites 99 but I've seen other's do it also. I don't need it to be as big as the form...I can do that. What I need is for it (the text box) to be sized in certain proportion to the form.
Code:
-----------------------------------------------------------
Title Bar at a "small" state
-----------------------------------------------------------| |
| |
| ------------------------- |
| |Text1 | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | | ------------------------- |
| |
| |
| |
| |
-----------------------------------------------------------
This is something what it looks like. Then when the form is maximized I would like for it to resize but stay in this general proportion. Does this help any?
-
Apr 3rd, 2000, 12:30 AM
#5
Correction To GRAHAM's Code
Here is a correction for the code GRAHAM posted. Commas were missing from the Move method and the order of the Width and height portions of the Move method were reversed.
Code:
Sub ResizeControls()
On Error Resume Next
Dim I As Integer
For I = 0 To Controls.Count - 1
With ProportionsArray(I)
' move and resize controls
Controls(I).Move .LeftProportions * ScaleWidth, _
.TopProportions * ScaleHeight, _
.WidthProportions * ScaleWidth, _
.HeightProportions * ScaleHeight
End With
Next I
End Sub
-
Apr 3rd, 2000, 12:47 AM
#6
Frenzied Member
I've had a look at the code for grahams example and by the looks of it it's just missing some commas.
try this
Code:
Private Type CtrlProportions
HeightProportions As Single
WidthProportions As Single
TopProportions As Single
LeftProportions As Single
End Type
Dim ProportionsArray() As CtrlProportions
Sub InitResizeArray()
On Error Resume Next
Dim I As Integer
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 resize controls
Controls(I).Move .LeftProportions * ScaleWidth, _
.TopProportions * ScaleHeight, _
.HeightProportions * ScaleHeight, _
.WidthProportions * ScaleWidth
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
there's an on error resume next statement in there which is to trap the errors presented by controls such as timers which have no height and width proportions if you run the original code without it you should get an argument not optional error but the on error resume next tells vb to run straight on ignoring it so it does nothing.
What the code does is remembers where all your controls are when you load the form and then when the form is resized it moves and resizes the controls to keep them in the same proportions as before.
this should solve the textbox problem quite nicely
-
Apr 3rd, 2000, 07:01 AM
#7
Fanatic Member
THIS IS HOW
As i see from your rough picture that you want the text box to be about a third of the width of the form so here is how to do it.
Sub Form_Resize()
text1.width=form1.width/3
text1.height=form1.height/2
text1.left=(form1.width-text1.width)/2
text1.top=(form1.height-text1.height)/2
End Sub
every time the form is resized the texbox is resized to remain PROPORTIONAL
Doc Zaf
{;->
-
Apr 13th, 2000, 06:56 AM
#8
Addicted Member
Thanks Sam & Martin
GRAHAM
-
Sep 9th, 2014, 11:57 AM
#9
Addicted Member
Re: text box resize when form resizes
Hi guys i have the same problem is it posible to make. That controls stays same on load as i place them on form.
Just when i try to resize the form then properties such as width, height, left, top . starting to resize.
Like this when i open form it resize's the element's per form.size
Code:
Sub Form_Resize()
text1.width=form1.width/3
text1.height=form1.height/2
text1.left=(form1.width-text1.width)/2
text1.top=(form1.height-text1.height)/2
End Sub
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
|