• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

Size in twips for a text

Hi guys...

How do I know how much is the size in twips for a text in a specific font/size format?
0
nfernand
Asked:
nfernand
1 Solution
 
caraf_gCommented:
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
 
caraf_gCommented:
(Make sure the form's scale mode is twips for this)
0
 
VbmasterCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
wsh2Commented:
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
 
caraf_gCommented:
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
 
caraf_gCommented:
Geez. My English.
0
 
wsh2Commented:
<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
 
nfernandAuthor Commented:
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
 
caraf_gCommented:
"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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now