Solved

Automatic Text Resizing

Posted on 2000-03-16
9
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
caraf_g earned 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 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