473,395 Members | 1,702 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,395 software developers and data experts.

Problem measuring a string

Hi all,

I wonder if someone can help me out with this problem.

I want to confine input of characters in a textbox to the amount that will
fit in a given width on printed output.

For example on the form that my program prints there is a space for text
that is 100mm wide, the string for which is provided by the customer by
entering it into a textbox prior to it being output to the printer.

How can I stop the user from entering more chars than will fit. Just setting
the maxlength property of the textbox isn't a very elegant solution as the
printed font isn't fixed width.

I assume I need to be able to check the length of the string as each char is
typed and decide whether it will fit or not and therefore decide whether
further input should be allowed or not.

As I can't figure out how to obtain the graphics object for the printer
without starting a print job I am stuck.

Can anyone provide a solution or at least point me in the right direction.

Many thanks,

Martin.
Feb 28 '06 #1
5 1090
> As I can't figure out how to obtain the graphics object for the printer
without starting a print job I am stuck.


Give this a try:

Dim pd As New Drawing.Printing.PrintDocument
Dim g As Graphics = pd.PrinterSettings.CreateMeasurementGraphics()

It sounds like what you want. I have no experience with it, so no guarantees.
Feb 28 '06 #2
Thankyou,

using your suggestion I have managed to come up with a solution that works.

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
As I can't figure out how to obtain the graphics object for the printer
without starting a print job I am stuck.


Give this a try:

Dim pd As New Drawing.Printing.PrintDocument
Dim g As Graphics = pd.PrinterSettings.CreateMeasurementGraphics()

It sounds like what you want. I have no experience with it, so no
guarantees.

Feb 28 '06 #3
CMM
Remember to always call Dispose on Graphics objects that you create. They
hold on to Win32 GDI resources if you don't.

--
-C. Moya
www.cmoya.com
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
As I can't figure out how to obtain the graphics object for the printer
without starting a print job I am stuck.


Give this a try:

Dim pd As New Drawing.Printing.PrintDocument
Dim g As Graphics = pd.PrinterSettings.CreateMeasurementGraphics()

It sounds like what you want. I have no experience with it, so no
guarantees.

Mar 2 '06 #4
"CMM" <cm*@nospam.com> schrieb:
Remember to always call Dispose on Graphics objects that you create. They
hold on to Win32 GDI resources if you don't.


That's a good idea. In VB 2005 you could even utilize the 'Using' block
statement:

\\\
Using g As Graphics = ...
...
End Using
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 2 '06 #5
Thanks guys,

checking back on my code, I had indeed forgotten to dispose of it. Now using
a 'using/end using' block as suggested by Herfried.

Martin.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"CMM" <cm*@nospam.com> schrieb:
Remember to always call Dispose on Graphics objects that you create. They
hold on to Win32 GDI resources if you don't.


That's a good idea. In VB 2005 you could even utilize the 'Using' block
statement:

\\\
Using g As Graphics = ...
...
End Using
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 24 '06 #6

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

Similar topics

4
by: Marek Möhling | last post by:
My server (Apache/1.3.28 - PHP/4.3.3) is configured to receive gzipped data via: Header append Accept-Encoding "gzip, deflate" PHP is configured to send gzipped data via: php_value...
1
by: Scott | last post by:
I have a view that contains the following SQL1 and it takes about 500ms to run with Explain Plan EXP1. However, if I add an order by clause(e.g. select * from view1 order by ID desc), it will then...
2
by: Dane | last post by:
I am having a problem printing in C#. I am using DrawString() with the RectagleF class to determine the location to print. I am doing it this way so that I can get the text to auto wrap. The...
8
by: Shimrit Ben-Yair | last post by:
Hi, I'm having problems with the measureString function. I am trying to measure the length of a string the user types into a text box. However, the size in pixels that this function returns is...
2
by: Jason James | last post by:
Hi all, Only when a printpage event is fired from my printdocument am I able to get a handle on my printer through the passed parameter as follows ByVal e As...
5
by: Mr | last post by:
Hi We have a application with Framework 1.1 and Vs .NET 2003. the application has a service with pooling; like a File system Watcher, but works. the system works fine in the development...
6
by: mehdi_mousavi | last post by:
Hi folks, Consider a text containing 200 characters (more or less) including and/or excluding the CR/LF within. I would like to compute the height of this text whenever it's width is limited by X...
1
by: Sergey Zenyuk | last post by:
In VB.net windows application I use following code implementing SqlBulkCopy import: Using connODBC As New OdbcConnection(ConnStrODBC) connODBC.Open() Dim dbcmd As New OdbcCommand(String....
9
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
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...
0
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...

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.