Solved

Size in twips for a text

Posted on 2000-03-28
9
386 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now