Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i resize textbox when form is resized? 3

Status
Not open for further replies.

robbaggio

Programmer
Jun 11, 2002
31
US
say i have a text box at the bottom of my main form called Status. Status has the same basic width as the main form (Main). I want it to work, so that when Main is resized, Status will automatically resize so its width equals the with of Main.

This is what i have right now:

Private Sub Main_Resize()
If Me.WindowState <> 0 Then
Exit Sub
End If
If Me.Height < 4000 Then
Me.Height = 4000
End If
If Me.Width < 4000 Then
Me.Width = 4000
End If

Status.Width = Main.Width - 100
Status.Refresh
Me.Refresh
End Sub


This however, doesnt work how i want it to. It seems to resize Status, but it does not show the new part of the textbox(it is as if it is covered by something).

Does anyone know how i can get this to work like i want it?
any help would be greatly appreciated

robbaggio
 
Try,

Status.width = main.scalewidth - 100
Status.height = (main.scaleheight/2) - 200 'half the height of the main form keeping 100 pixel border on both sides.
status.top = main.scaleheight - status.height - 100 'keep the box 100 pixels off the bottom of the form.

You can play with some of the numbers to make adjustments but you can see how it works.
Thanks and Good Luck!

zemp
 
this still doesnt work for me. (it resizes status, but it is as if the Main form is on top of the Status textbox on the new (right hand side) part of the Status textbox. So only the original size really shows text, and the rest is cutoff.

any ideas?

robbaggio
 
I am unclear on how you know that the text box is resizing if the end is cutoff. Does the box visually resize, but just not allow text on the right hand side? Also, you text box may be placed on a frame whose width is not being changed. If the frame has no border and is the same color as the form, you won't even see it. It will however prevent you from seeing any control placed on it that is wider (even if you use the &quot;Bring To Front&quot; feature). To see if there is a frame, click near the text box, and see if something other than the text box or form is selected. You can also go to the pull down box in the properties window and look thru the object names to see if there is a frame on the list. Also note, other controls that act as a container (eg; the MS Tab control) could cause the same problem. Good luck!

djsiders
 
I agree with gjsiders. If you start resizing your form then you need to resize all of your controls. I assumed that you had only one text box control on your form. My mistake. Thanks and Good Luck!

zemp
 
If you want to try and resize the controls yourself, the algorithm is fairly straightforward, but there are a number of pitfalls that you need to be aware of.

First, calculate a HeightFactor and a WidthFactor.

dim HeightFactor as Single
dim WidthFactor as Single

HeightFactor = NewWindowHeight / OldWindowHeight
WidthFactor = NewWindowWidth / OldWindowWidth

Loop thru your controls collection, and for each that apply, call the following subroutine passing the control and a byref parameter.

dim TheControl as Control

For Each TheControl in Me.Controls
SizeThisControl ThisControl
Next

Private Sub SizeThisControl(ControlID As Control)

On Error GoTo HandleError

Dim NewWidth As Long
Dim NewTop As Long
Dim NewLeft As Long
Dim NewHeight As Long

With ControlID
NewTop = Int((.Top * gHeightFactor) + 0.5)
NewHeight = Int((.Height * gHeightFactor) + 0.5)
NewLeft = Int((.Left * gWidthFactor) + 0.5)
NewWidth = Int((.Width * gWidthFactor) + 0.5)
.Top = pLng_NewTop
.Left = pLng_NewLeft
.Width = pLng_NewWidth
.Height = pLng_NewHeight
End With

Exit Sub

HandleError:

Resume Next

End Sub

Some of the pitfalls that you need to be aware of:

1. Watch out for FontSize - you may or may not want to adjust the .FontSize property, and not all controls have that property. If you do choose to reset the FontSize, then it would be done similarity to the other properties.

2. If you controls are on tabs, then if would not be a good idea to adjust the size and/or position of that control unless you are actually on that tab.

3. You may have events triggered on the controls as they are moved and resized, so you need to handle those.

4. Be sure to keep the error handler because of such things as &quot;Left Property cannot be read a run-time&quot; -- this will happen if your control happens to be a timer, or the &quot;Height&quot; property of a combobox.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top