Solved

Size in twips for a text

Posted on 2000-03-28
9
388 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
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 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