|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem measuring a stringI 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. > As I can't figure out how to obtain the graphics object for the printer Give this a try:> without starting a print job I am stuck. 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. Thankyou,
using your suggestion I have managed to come up with a solution that works. Show quoteHide quote "AMercer" <AMer***@discussions.microsoft.com> wrote in message news:9848B471-FB1B-4536-A7A0-944E45A37179@microsoft.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. Remember to always call Dispose on Graphics objects that you create. They
hold on to Win32 GDI resources if you don't. Show quoteHide quote "AMercer" <AMer***@discussions.microsoft.com> wrote in message news:9848B471-FB1B-4536-A7A0-944E45A37179@microsoft.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. "CMM" <cmm@nospam.com> schrieb: That's a good idea. In VB 2005 you could even utilize the 'Using' block > Remember to always call Dispose on Graphics objects that you create. They > hold on to Win32 GDI resources if you don't. 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/>
Programming for USB Modem
Check if an object is a type object SOAP Client navigation? Threading - Object reference not set to an instance of an object VB.Net and SQL Server Developer Converting c# to vb.net Frameworks and Check/Install select query changing bound controls data Enum Properties Revisited |
|||||||||||||||||||||||