473,734 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12724
"Steve" <no****@nospam. spam> wrote in message
news:lG******** ********@newsre ad2.news.atl.ea rthlink.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 "AutoSizeTextBo x"; 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@NOdataSPAMg nostics.com> wrote in message
news:ua******** *****@TK2MSFTNG P15.phx.gbl...
"Steve" <no****@nospam. spam> wrote in message
news:lG******** ********@newsre ad2.news.atl.ea rthlink.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 "AutoSizeTextBo x"; 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(st rIn 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.OpenRecord set(strSQL, dbOpenSnapshot)
For intI = 1 To Len(strIn)
strChar = Mid(strIn, intI, 1)
lngASC = Asc(strChar)
MetricRS.FindFi rst "[ASCIINumber] = " & CStr(lngASC)
If Not MetricRS.NoMatc h 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********@com pumarc.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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(st rIn 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.OpenRecord set(strSQL, dbOpenSnapshot)
For intI = 1 To Len(strIn)
strChar = Mid(strIn, intI, 1)
lngASC = Asc(strChar)
MetricRS.FindFi rst "[ASCIINumber] = " & CStr(lngASC)
If Not MetricRS.NoMatc h 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
9453
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 underscore?
4
13377
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? Thanks Steve
3
9469
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 boxes so that they may be edited. I would like some textboxes to be wider, some narrower. By default, they are all the same pre-defined width. Does anyone know how I can do this? Thanks very much,
4
2922
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 much jsut coping code. I having some issue with some textboxes not updating when i a hit save. for example I have this code in my aspx.cs file: declared:
1
1431
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 too small for the cell content. Is there anyway to change the width of the textbox? Thanks in advance, Regards, Yee
2
2346
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 product it also must change the price how can I achieve that. Thanks Datagrid html
2
3396
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 of more than one line (as a note field). What I want is to set the height of the row based on the number of lines in it. The row height of each row in the table may be different from each other. Is there a way to do this?
0
1362
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 of rows of records (either none or upto 10). I have created these textboxes at design time. <tr> <td><asp:TextBox Width="88px" runat="server" id="txtBore_Number1"/></
0
2397
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 the next time they login and go to the Profile View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
1
15044
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 the Columns <tagof the GridView control. I have to add controls dynamically as I am trying to write a reusable , general , spreadsheet like display control that can take advantage of the built- in update and delete features of the SqlDataSource/Gridview controls. This user control can get its...
0
8780
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9246
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6742
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4816
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3264
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.