Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Size in twips for a text

Posted on 2000-03-28
9
Medium Priority
?
400 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 200 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
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.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Suggested Courses

609 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