Solved

Size in twips for a text

Posted on 2000-03-28
9
393 Views
Last Modified: 2012-05-04
Hi guys...

How do I know how much is the size in twips for a text in a specific font/size format?
0
Comment
Question by:nfernand
[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
9 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 50 total points
ID: 2664066
Each form as a TextWidth and a TextHeight property.

Just make sure the Form's Font has the required properties and then go

thewidthofthetext = TheForm.TextWidth("The Text")
etc.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2664068
(Make sure the form's scale mode is twips for this)
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2664107
Where you do you want to draw this text? Textboxes, pictureboxes and forms have a TextWidth(text) property which will tell you the width of a text string according to the controls current font/size setting.
0
Industry Leaders: 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 14

Expert Comment

by:wsh2
ID: 2664231
Elaborating on Caraf_g's and vbMaster's comments..

If you don't have a Textbox on your form.. just add one.. and set it's Visible property to False.

<----- Code Begin ----->

Dim sngTextWidth as Single
With Text1
  If .Text <> "" _
  Then
    Text2.Text = .Text
    Text2.FontBold = .FontBold
    Text2.FontItalic = .FontItalic
    Text2.FontName = .FontName
    Text2.FontSize = .FontSize
    Text2.FontStrikethru = .Fontstrikethru
    Text2.FontUnderline = .FontUnderline
    sngTextWidth = Text2.TextWidth
  End If
End With
msgBox (sngtextWidth)

<----- Code End ----->
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2664278
Text boxes don't have a text width properties. That's why you have to do some weird stuff like setting your >Form's< font's properties and then using the Form's textwidth method.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2664279
Geez. My English.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2664573
<chit>.. I trusted vbMasters post.. sure enuff you are correct on the Textbox not having a textwidth property caraf_g.. <sigh>. Nevertheless, the PictureBox does (although it is a pretty heavy control just to do Text sizing)

To be honest.. I use a hidden label with its Autosize property set to True. With it, I set the Fonts, place the text in the caption, subtract the borders.. and voile, a textwidth in Twips is derived.

Anyhow.. at least my English is "good".. <LOL> and a <wink>. Just kidding caraf_g.. <smile>.

0
 
LVL 2

Author Comment

by:nfernand
ID: 2664627
Thank you guys...

Caraf_q is Ok: There is no TextWidth property everywhere.
I need this value to calculate columns width in a MSHFlexGrid.
I will use Caraf_q method because I'm not writing directly to the form, so, using the form's FontSize propierty doesn't make any other font to grow or shrink.

Bye.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2664735
"the PictureBox does"

Yes I think a lot of controls that can be control containers tend to provide this functionality.

nfernand, that's exactly why I'm doing it too. In the rare case where your form's font *does* affect your window, use wsh2's idea of using a picture box or another control that has textwidth and -height methods. A picture box is quite handy because you can set its borderstyle to none and make it 0 high and wide, and set its tabstop property to false so your user will never know it's there...

G'luck
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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