Greetings!
I was wondering how to mix font sizes in a text area. What I'm trying to do is to draw a large number with a smaller piece of text right after it. Something like '69 cases'. The number is centered.
My approach was to use two textarea objects. To add the second textarea I need to find out how wide the first text area needs to be to fit the text of the large number so that I can place a second text area next to it and it looks like one piece.
Am I using the right approach?
Here's my sample code: (txt3.width doesn't seem to return what I was expecting)
Dim Txt3 As TextArea = New TextArea(l_Quantity.ToString, X + LabelLeftRightMargin + BarcodeWidth, Y + LabelTopBottomMargin + 40, LabelWidth - (LabelLeftRightMargin * 2) - BarcodeWidth, 18, Font.TimesBold, 18, TextAlign.Center)
Dim Txt4 As TextArea = New TextArea("cases", X + LabelLeftRightMargin + BarcodeWidth + txt3.Width / 2, Y + LabelTopBottomMargin + 50, LabelWidth - (LabelLeftRightMargin * 2) - BarcodeWidth - LabelWidth / 3, 7, Font.TimesRoman, 7, TextAlign.Left)
Thanks for your assistance. I'm just beginning to get my feet wet in .NET so please forgive my ignorance.
Dave
Mixing Font Sizes
Re: Mixing Font Sizes
Support · Jul 19, 2006Hello Dave,
You can find out the width for the text if the string is just one line using the GetTextWidth method of the Font object which takes the string and the font size. You can set the width of the TextArea to the corresponding TextWidth you get from the GetTextWidth and you can start a second TextArea after the first one with some padding.
The following is the sample code to use the GetTextWidth method of the Font class:
If you are using Helvatica, 12 Point:
TextWidth = Font.Helvetica.GetTextWidth( "My Text", 12 )
If you are using a TrueType, Type 1 or other font object:
TextWidth = MyFont.GetTextWidth( "My Text", 12 )
Thanks,
ceTe Software Support Team