473,405 Members | 2,287 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,405 software developers and data experts.

Printing a form's image

Hi

I'm unsuccessfully trying to print a form's image under
VB.NET. To print under .NET is a real pain in the [...], I
find it to be complex, lenghty, confusing, upsetting and
ultimately not to be working at all.

My strategy is first to save the form's image as a bitmap
(this works, I can save the image to a file). Then I use
the printer's Graphics object's drawImage method to send it
to the printer. Most of the time a blank paper comes out;
when something finally get printed (depending on which
printer I'm using), it's too small to be useful.
Sometimes, the printer's resolution is a negative value
(???). Sometimes I must specify margins in tenth of
millimeters instead than in hundreth of an inch. And the
list of anomalies, annoyances and inconsistences continues...

I'm wondering, am I alone in finding that Microsoft really
goofed when it designed to .NET's printing architecture?
Really makes me regret working with Java.

If anyone can tell me why my code produces such
inconsistent documents, it would really be appreciated. I
can still save the image and then use Paint (or whatever
else) to print the image, but that really looks
unprofessionnal.

Here's my code (but not all of it, as you may understand!):

' Class attributes
Private WithEvents doc As PrintDocument
Private form_image As Bitmap ' Image to be printed
Private print_d As PrintDialog
Private page_sd As PageSetupDialog

[...]
' The PrintDocument and dialog boxes are initialized in
another method; I won't list it here for clarity

Private Sub doc_PrintPage(ByVal sender As Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
doc.PrintPage
Dim g As Graphics = e.Graphics

' Image size (pixels)
Dim xImagePixels As Integer = form_image.Width
Dim yImagePixels As Integer = form_image.Height
Dim srcRect As New Rectangle(0, 0, xImagePixels,
yImagePixels)

Dim ps As PageSettings = doc.DefaultPageSettings

' Paper size (inch)
Dim pgX As Single = ps.PaperSize.Width * 0.01
Dim pgY As Single = ps.PaperSize.Height * 0.01

' page margins (inch)
Dim mLeft As Single = ps.Margins.Left * 0.01
Dim mRight As Single = ps.Margins.Right * 0.01
Dim mTop As Single = ps.Margins.Top * 0.01
Dim mBottom As Single = ps.Margins.Bottom * 0.01

' Printer resolution (dot per inch)
Dim rx As Single = ps.PrinterResolution.X
Dim ry As Single = ps.PrinterResolution.Y

' Dimensions of the image to be printed - in pixels
' using the specified printer's resolution
Dim destRec As New Rectangle(0, 0, (pgX - mLeft - mRight)
* rx, (pgY - mTop - mBottom) * ry)

' Draw the image to the printer - should work???
g.DrawImage(form_image, srcRect, destRec, GraphicsUnit.Pixel)

End Sub

So that's it. I'm really suspicious about the
PrinterResolution property; is it really meaningful? What
else could I do to know the scaling factor I must use to
transform the original image to its new size?

Any help (or sharing of similar problems) may be useful.

JF

Nov 22 '05 #1
0 933

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

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
0
by: JF Turcotte | last post by:
Hi I'm unsuccessfully trying to print a form's image under VB.NET. To print under .NET is a real pain in the , I find it to be complex, lenghty, confusing, upsetting and ultimately not to be...
1
by: Frank.Sebesta | last post by:
I have a employees database with a picture that shows on a form with employee information. Similar to the Northwinds sample database. When I print the record, my output is only the data and does...
5
by: VMI | last post by:
I have a BMP image (the form is also in PDF) that contains a scanned copy of a paper form that we need to fill out. Is it possible to use this image in my application so that the application can...
4
by: CsharpNewcommer | last post by:
Hi I have designed a form containing data and I want to print that form and the data as it appears in the Windows Form. I am a beginner with C# and I have read several "help"s on PrintPage,...
5
by: Tom | last post by:
I am converting an old application that was printing directly to a specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and...
3
by: DJ Pomeroy | last post by:
I just can't seem to get it... I have a form. On this form is a panel. In this panel is a bunch of objects - graphics, text, and so on. I want to be able to print what's in the panel to a...
3
by: D Witherspoon | last post by:
No matter what I do the default paper size is always either A3 or 11 by 8.5 .. Here is the code. Dim dlg As DialogResult pd.DocumentName = "Weld Image" Dim pkPaperSize As New...
2
by: sitemap | last post by:
Hello guys, I have a big problem with printing of windows.Forms :( I have application with "print" button. I am trying to use "e.Graphics.CopyFromScreen"... but in final result, over the...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.