Solved

Automatic Text Resizing

Posted on 2000-03-16
9
162 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

808 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