473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

text width of a string at a certain font size

hi,

in order to place a string of text at a specific place on a printed page, i
need to know its width in pixels at a certain font size. in vb6 there used
to be a function something like 'TextWidth' to which you would feed a string
and get its width.

how can i do this in vb net?

thanks

ray

please respond to the list
Nov 20 '05 #1
4 15086
have a look at system.drawing...specifically the RectangleF arg of the
DrawString method.

hth,

steve

"ray well" <no****@nospam.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
hi,

in order to place a string of text at a specific place on a printed page, i need to know its width in pixels at a certain font size. in vb6 there used
to be a function something like 'TextWidth' to which you would feed a string and get its width.

how can i do this in vb net?

thanks

ray

please respond to the list

Nov 20 '05 #2
Hi Ray,

The 'TextWidth' equivalent in .NET is called MeasureString and it's a
member of the Graphics class. You may find, however, that using DrawString in
the manner that Steve suggests, means not needing to be concerned about the
width.

Regards,
Fergus
Nov 20 '05 #3
Just to clarify a bit.

Using DrawString with the RectangleF argument causes the string to wrap to
the bounds specified in the Rectangle. Using drawstring with X, Y
coordinates will draw it across the page until it runs out of text.

If you're just trying to layout some text on a surface or a printdocument,
and the font is fixed, check out our product, GDI+ Architect at
www.mrgsoft.com. There's a 15 day trial and you may get all the info you
need trying different things out within the trial period and looking at the
generated System.Drawing code.

--

Justin Weinberg
Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"ray well" <no****@nospam.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
hi,

in order to place a string of text at a specific place on a printed page, i need to know its width in pixels at a certain font size. in vb6 there used
to be a function something like 'TextWidth' to which you would feed a string and get its width.

how can i do this in vb net?

thanks

ray

please respond to the list

Nov 20 '05 #4
* "ray well" <no****@nospam.com> scripsit:
in order to place a string of text at a specific place on a printed page, i
need to know its width in pixels at a certain font size. in vb6 there used
to be a function something like 'TextWidth' to which you would feed a string
and get its width.


Have a look at the 'Graphics.MeasureString' method.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

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

Similar topics

19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
4
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text...
1
by: blue | last post by:
I have a table that I want to have a set width and height. The table has a title and the text may be larger than the width of the table. If the text is too large to fit into the table, it either...
13
by: =?Utf-8?B?S2VzdGZpZWxk?= | last post by:
Hi Our company has a .Net web service that, when called via asp.net web pages across our network works 100%! The problem is that when we try and call the web service from a remote machine, one...
1
by: Oron.Morad | last post by:
Hello, I develop C#.NET (WinForm) over 2003server. I am looking for a way to adjust a component size (width pixels) according to a given text of a certain font (i.e font family, size and style)...
1
by: dhaneshrs | last post by:
I have a small code that shows inactive and active users from the ms access DB. <%@ Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" Title="Welcome" %> <%@ Import...
4
by: pablorp80 | last post by:
Hello, Here is what I need: I need the focus and the cursor set to a textbox named txtGT, every time no matter if it is the first page load or whether it is a postback. Here is the problem: I...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.