Solved

Automatic Text Resizing

Posted on 2000-03-16
9
160 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
Comment Utility
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
Comment Utility
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
Comment Utility
PS - stick the label at position 0,0 and the text box relatively far down the form.
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 50 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 10

Expert Comment

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

Expert Comment

by:mcrider
Comment Utility
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
Comment Utility
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
Comment Utility
Well? Any good?
0
 

Author Comment

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

Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now