If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
auto resize a text in a text box
Hi, is there a way to auto resize a text to fill the text box. I want to use
this for a name tag to fill up the text box according to name's length. Thank you in advance. |
#2
|
|||
|
|||
auto resize a text in a text box
Arlene wrote:
Hi, is there a way to auto resize a text to fill the text box. I want to use this for a name tag to fill up the text box according to name's length. Thank you in advance. What do you mean by "resize"? If you mean change its FontSize and it fits on one line, then try something like: Dim fs As Integer For fs = 14 To 5 Step -1 If TextWidth(Me.thetextbox) Me.thetextbox.Width Then Exit For End If Next fs Me.thetextbox.FontSize = fs -- Marsh MVP [MS Access] |
#3
|
|||
|
|||
Trying to do the same thing
Hi
Sorry for digging up an old thread but I have the same problem as Arlen. Trying to use the code you've provided, Marsh, but it's not quite working as expected. Can you help? This is my full code, inc debugging info Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer) Dim fs As Integer Debug.Print Text0 & vbCrLf & "Height: " & Text0.Height & " Width: " & Text0.Width & " TextWidth/Height:" & TextWidth(Me.Text0) & "/" & TextHeight(Me.Text0) & " FONT SIZE: " & Me.Text0.FontSize For fs = 25 To 5 Step -1 Me.Text0.FontSize = fs If TextWidth(Me.Text0) Me.Text0.Width Then Exit For End If Next fs Debug.Print "Height: " & Text0.Height & " Width: " & Text0.Width & " TextWidth/Height:" & TextWidth(Me.Text0) & "/" & TextHeight(Me.Text0) & " FONT SIZE: " & Me.Text0.FontSize & vbCrLf End Sub The debugging info this gives me is: Short Height: 559 Width: 5265 TextWidth/Height:480/269 FONT SIZE: 4 Height: 559 Width: 5265 TextWidth/Height:480/269 FONT SIZE: 25 Very very very very long indeed Height: 559 Width: 5265 TextWidth/Height:2818/269 FONT SIZE: 25 Height: 559 Width: 5265 TextWidth/Height:2818/269 FONT SIZE: 25 Quite long text Height: 559 Width: 5265 TextWidth/Height:1330/269 FONT SIZE: 25 Height: 559 Width: 5265 TextWidth/Height:1330/269 FONT SIZE: 25 (the first line in each section is the value in the text box). All of the text comes out the same size. I would expect the second value to have resulted in small text, but it gets cropped instead. As you can see, the TextWidth of that text is 2818, which is less than the width of the textbox (5265). But as the text is longer than the text box I'd have expected it to have been higher than 5265. I've also tried the same code in Report_Page event but I either get text at 25 points or 5 points - nowhere in between. Thanks in advance if you can help! Nick Marshall Barton wrote: auto resize a text in a text box 10-Oct-08 Arlene wrote: What do you mean by "resize"? If you mean change its FontSize and it fits on one line, then try something like: Dim fs As Integer For fs = 14 To 5 Step -1 If TextWidth(Me.thetextbox) Me.thetextbox.Width Then Exit For End If Next fs Me.thetextbox.FontSize = fs -- Marsh MVP [MS Access] EggHeadCafe - Software Developer Portal of Choice Silverlight 2 Beta 2 - Doing Data Part I http://www.eggheadcafe.com/tutorials...eta-2--do.aspx |
#4
|
|||
|
|||
Trying to do the same thing
Nick Thompson wrote: [snipped to essentials]
Trying to use the code you've provided, Marsh, but it's not quite working as expected. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer) Dim fs As Integer For fs = 25 To 5 Step -1 Me.Text0.FontSize = fs If TextWidth(Me.Text0) Me.Text0.Width Then Exit For End If Next fs End Sub All of the text comes out the same size. I would expect the second value to have resulted in small text, but it gets cropped instead. As you can see, the TextWidth of that text is 2818, which is less than the width of the textbox (5265). But as the text is longer than the text box I'd have expected it to have been higher than 5265. Nothing in that code tells TextWidth what font size to use so it's always using whatever the report's default font size. I should be more like: Dim fs As Integer For fs = 14 To 5 Step -1 Me.FontSize = fs If TextWidth(Me.thetextbox) Me.thetextbox.Width Then Exit For End If Next fs Me.thetextbox.FontSize = fs -- Marsh MVP [MS Access] |
Thread Tools | |
Display Modes | |
|
|