?
Solved

Automatic Text Resizing

Posted on 2000-03-16
9
Medium Priority
?
170 Views
Last Modified: 2010-05-02
I have a sizeable form which I want to write text on. The text must be within a Label, TextBox or PictureBox. When the form is manually resized, I want the text to resize too, so that it fills the entire form.  Any good solutions?
0
Comment
Question by:OTveit
  • 6
  • 2
9 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 2623235
It ain't pretty but it works.

Option Explicit

Private Sub Form_Load()

ResizeLabel

End Sub

Private Sub Form_Resize()

ResizeLabel

End Sub

Private Sub Text1_Change()

Label1.Caption = Text1.Text
ResizeLabel

End Sub
Private Sub ResizeLabel()

Set Me.Font = Label1.Font

Me.Font.Size = 1000
Do While TextWidth(Label1.Caption) > ScaleWidth
    Me.Font.Size = Me.Font.Size / 1.3
Loop

Set Label1.Font = Me.Font

End Sub
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2623236
In the Form Resize event, do something like this:

   Text1.width = form1.width - 120
   Text1.height = text1.height - 360

You may need to adjust this if the top of text1 is not 0... for example:

   Text1.height = text1.height - 360 - text1.top

or something like that...


Cheers!®©
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2623237
PS - stick the label at position 0,0 and the text box relatively far down the form.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Accepted Solution

by:
caraf_g earned 150 total points
ID: 2623247
Here: this is a bit less flickery.

Option Explicit

Private Sub Form_Load()

ResizeLabel

End Sub

Private Sub Form_Resize()

ResizeLabel

End Sub

Private Sub Text1_Change()

Label1.Caption = Text1.Text
ResizeLabel

End Sub
Private Sub ResizeLabel()

Me.Font.Size = 1000
Do While TextWidth(Label1.Caption) > ScaleWidth
    Me.Font.Size = Me.Font.Size / 1.3
Loop

Label1.Font.Name = Me.Font.Name
Label1.Font.Size = Me.Font.Size

End Sub

I've done Font.Name and Font.Size. You can code the other font properties (bold, italic, etc.) yourself
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2623249
mcrider, you misunderstood. OTveit wants the actual text, not just the control, to fill the whole form.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2623299
Yea, I think you're right...  It sounded like OTveit wanted the textbox (or whatever) to resize...


Cheers!®©
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2623372
No probs. I don't think my suggestion is elegant enough to qualify as an "answer" either... Ah well, if OTveit thinks it does he can always accept a comment ;-)
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2623579
Well? Any good?
0
 

Author Comment

by:OTveit
ID: 2628088
Yepp, it works ok. I just had to do the same for the height.

Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question