Regarding Printing In VB.NET?
-
2012年3月12日 上午 10:18
I have a problem that the current output image that is displayed in my form does not print in its actual size..i have an output image as rectangle..drawn in millimeter...displays in form..but when i print the actual image gets printed small..
can anyone suggest me a answer......
- 已編輯 aashiq313 2012年3月13日 上午 04:11
所有回覆
-
2012年3月14日 上午 03:42版主
Hi Aashiq313,
Welcome to the MSDN forum.
Did you set the DPI of your project? If so, I’d suggest you check the DPI setting of your project. If its DPI is different to the system settings, you may get the scenario in your post. Could you please provide some codes about printing preview?
The following is my codes of printing preview:
Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Printing Public Class Form1 <System.Runtime.InteropServices.DllImport("gdi32.dll")> _ Public Shared Function BitBlt(hdcDest As IntPtr, nXDest As Integer, nYDest As Integer, nWidth As Integer, nHeight As Integer, hdcSrc As IntPtr, _ nXSrc As Integer, nYSrc As Integer, dwRop As Integer) As Long End Function Private memoryImage As Bitmap Private Sub CaptureScreen() Dim mygraphics As Graphics = Me.CreateGraphics() Dim s As Size = Me.Size memoryImage = New Bitmap(s.Width, s.Height, mygraphics) Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage) Dim dc1 As IntPtr = mygraphics.GetHdc() Dim dc2 As IntPtr = memoryGraphics.GetHdc() BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, _ 0, 0, 13369376) mygraphics.ReleaseHdc(dc1) memoryGraphics.ReleaseHdc(dc2) End Sub Private Sub printDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPage e.Graphics.DrawImage(memoryImage, 0, 0) End Sub Private Sub printButton_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click CaptureScreen() PrintPreviewDialog1.Document = printDocument1 PrintPreviewDialog1.Show() End Sub End ClassAnd I drew the image by the following codes:
Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim units As GraphicsUnit = GraphicsUnit.Millimeter Dim rectangle1 As New Rectangle(10, 10, 60, 80) Dim rectangle2 As New Rectangle(30, 5, 80, 60) e.Graphics.PageUnit = GraphicsUnit.Millimeter e.Graphics.DrawRectangle(Pens.Black, rectangle1) e.Graphics.DrawRectangle(Pens.Red, rectangle2) If (rectangle1.IntersectsWith(rectangle2)) Then rectangle1.Intersect(rectangle2) If Not (rectangle1.IsEmpty) Then e.Graphics.FillRectangle(Brushes.Green, rectangle1) End If End If End SubI hope this will be helpful and I'm looking forward to your feedback.
Best regards,
Shanks Zen
MSDN Community Support | Feedback to us
- 已編輯 Shanks ZenMicrosoft Contingent Staff, Moderator 2012年3月14日 上午 03:43
- 已標示為解答 Shanks ZenMicrosoft Contingent Staff, Moderator 2012年3月28日 上午 08:38

