472,333 Members | 1,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

Change Textbox Width

I need a way to programatically change the width of a textbox to display all
the data knowing the font, font size and number of characters. Does any oone
know of a reference somewhere ot a way to determine the width in twips for
say Times New Roman 12, 35 characters or say Arial 11, 26 characters?

Thanks,

Steve
Nov 13 '05 #1
5 12512
"Steve" <no****@nospam.spam> wrote in message
news:lG****************@newsread2.news.atl.earthli nk.net
I need a way to programatically change the width of a textbox to
display all the data knowing the font, font size and number of
characters. Does any oone know of a reference somewhere ot a way to
determine the width in twips for say Times New Roman 12, 35
characters or say Arial 11, 26 characters?

Thanks,

Steve


IIRC, Stephen Lebans has code to do this on his site at

www.lebans.com

Maybe the project is called "AutoSizeTextBox"; I'm not sure.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Nov 13 '05 #2
Thanks, Dirk!

Yes, that's the name of Stephen's project.

Steve
"Dirk Goldgar" <dg@NOdataSPAMgnostics.com> wrote in message
news:ua*************@TK2MSFTNGP15.phx.gbl...
"Steve" <no****@nospam.spam> wrote in message
news:lG****************@newsread2.news.atl.earthli nk.net
I need a way to programatically change the width of a textbox to
display all the data knowing the font, font size and number of
characters. Does any oone know of a reference somewhere ot a way to
determine the width in twips for say Times New Roman 12, 35
characters or say Arial 11, 26 characters?

Thanks,

Steve


IIRC, Stephen Lebans has code to do this on his site at

www.lebans.com

Maybe the project is called "AutoSizeTextBox"; I'm not sure.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Nov 13 '05 #3
Just in case Stephen's code doesn't do what you want:

On http://www.adobe.com you should be able to find:

Adobe Font Metric File Format Specification (#5004)

If you have the .afm file, it contains the information you need to
determine precisely how much space the characters in a font will use.
I usually ignore the kerning information since my uses don't require
that much accuracy. The following file (zipped A97 format) contains
character size information (no kerning info) for the 14 standard fonts
used for pdf documents:

http://www.oakland.edu/~fortune/FontMetrics.zip

To get the width the characters will take I use:

Public Function GetFontWidth(strIn As String, strFontName As String,
dblFontSize As Double) As Double
Dim lngTemp As Long
Dim MetricRS As Recordset
Dim MyDB As Database
Dim strSQL As String
Dim intI As Integer
Dim strChar As String
Dim lngASC As Long

GetFontWidth = 0#
If Len(strIn) = 0 Then Exit Function
lngTemp = 0
Set MyDB = CurrentDb
strSQL = "SELECT * FROM tbl" & strFontName & "Metrics;"
Set MetricRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
For intI = 1 To Len(strIn)
strChar = Mid(strIn, intI, 1)
lngASC = Asc(strChar)
MetricRS.FindFirst "[ASCIINumber] = " & CStr(lngASC)
If Not MetricRS.NoMatch Then
lngTemp = lngTemp + MetricRS("Width")
End If
Next intI
MetricRS.Close
Set MetricRS = Nothing
Set MyDB = Nothing
GetFontWidth = lngTemp * dblFontSize / 1000#
End Function

The fonts you mention are TrueType. More than you'll ever want to know
about TrueType fonts can be found at:

http://www.truetype.demon.co.uk/index.htm

Note that different characters produce different widths in proportional
fonts (most fonts). Courier is an example of a fixed-width font.
There are 20 twips to a PostScript point. There are 72 PostScript
points to an inch.

James A. Fortune

The default unit size (1/72 inch) is approximately the same as a
"point," a unit widely used in the printing industry. It is not
exactly the same as a point, however; there is no universal definition
of a point.
-- Postscript Language Reference Manual, Third Edition, Adobe Systems
Incorporated

Nov 13 '05 #4
The code on my site works for any font. Only one line of code is
required to return a value in TWIPS which can be directly applied to the
Text/Label control to perform autosizing. Further it is a multiline
aware solution.

http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth
and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line
to simulate RTF style text.
History

Version 4.5: Increased accuracy of auto sizing for a ListBox.

Version 4.3: Added sample Form to demonstrate auto sizing for a ListBox.

Version 4.2: Added report to demonstrate auto sizing to mix text
formatting on one row.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
<ji********@compumarc.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Just in case Stephen's code doesn't do what you want:

On http://www.adobe.com you should be able to find:

Adobe Font Metric File Format Specification (#5004)

If you have the .afm file, it contains the information you need to
determine precisely how much space the characters in a font will use.
I usually ignore the kerning information since my uses don't require
that much accuracy. The following file (zipped A97 format) contains
character size information (no kerning info) for the 14 standard fonts
used for pdf documents:

http://www.oakland.edu/~fortune/FontMetrics.zip

To get the width the characters will take I use:

Public Function GetFontWidth(strIn As String, strFontName As String,
dblFontSize As Double) As Double
Dim lngTemp As Long
Dim MetricRS As Recordset
Dim MyDB As Database
Dim strSQL As String
Dim intI As Integer
Dim strChar As String
Dim lngASC As Long

GetFontWidth = 0#
If Len(strIn) = 0 Then Exit Function
lngTemp = 0
Set MyDB = CurrentDb
strSQL = "SELECT * FROM tbl" & strFontName & "Metrics;"
Set MetricRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
For intI = 1 To Len(strIn)
strChar = Mid(strIn, intI, 1)
lngASC = Asc(strChar)
MetricRS.FindFirst "[ASCIINumber] = " & CStr(lngASC)
If Not MetricRS.NoMatch Then
lngTemp = lngTemp + MetricRS("Width")
End If
Next intI
MetricRS.Close
Set MetricRS = Nothing
Set MyDB = Nothing
GetFontWidth = lngTemp * dblFontSize / 1000#
End Function

The fonts you mention are TrueType. More than you'll ever want to know about TrueType fonts can be found at:

http://www.truetype.demon.co.uk/index.htm

Note that different characters produce different widths in proportional fonts (most fonts). Courier is an example of a fixed-width font.
There are 20 twips to a PostScript point. There are 72 PostScript
points to an inch.

James A. Fortune

The default unit size (1/72 inch) is approximately the same as a
"point," a unit widely used in the printing industry. It is not
exactly the same as a point, however; there is no universal definition
of a point.
-- Postscript Language Reference Manual, Third Edition, Adobe Systems
Incorporated


Nov 13 '05 #5
Stephen Lebans wrote:
The code on my site works for any font. Only one line of code is
required to return a value in TWIPS which can be directly applied to the Text/Label control to perform autosizing. Further it is a multiline
aware solution.

http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line to simulate RTF style text.
History

Version 4.5: Increased accuracy of auto sizing for a ListBox.

Version 4.3: Added sample Form to demonstrate auto sizing for a ListBox.
Version 4.2: Added report to demonstrate auto sizing to mix text
formatting on one row.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Stephen,

I didn't mean to imply that your code contributions for text boxes and
RTF won't work. Those are great features BTW.

James A. Fortune

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: S.W. Rasmussen | last post by:
A trivial (?) question: does anyone know how to change the shape of the cursor in a RichTextBox control from the normal vertical line to an...
4
by: Steve | last post by:
Visual Studio 2003 .NET C# I am trying to change the width of a textbox at run time, to fit in the text it contains. How can I do this? ...
3
by: Ronald S. Cook | last post by:
Hi all, I have an ASP.NET DataGrid wherein there is an edit link for each row. Upon clicking the link, certan fields in that row display in text...
4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty...
1
by: YeeCN | last post by:
Hi, I have a datagrid with one very wide column. The problem is that if the grid goes into edit mode the textbox that appear automatically is far...
2
by: Luis Esteban Valencia | last post by:
Hello I have a datagrid with a dropdownlist that has the products, another column has the price of the product and when the user changes the...
2
by: Tor Inge Rislaa | last post by:
How to change row height in a DataGrid I have DataGrid that is filled with data from a table in a DataSet. The content of the cells is text...
0
by: mamun | last post by:
Hi All, I have the following situation. I have 10 rows in a form. In each row there are six textbox controls. The users can enter any number...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then...
1
by: savajx1 | last post by:
I need to dynamically create a set of bound fields contained in a GridView control. I also have a single static CommandField that I can declare in...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.