|
-
Jun 14th, 2004, 08:46 AM
#1
Thread Starter
Lively Member
Sending document to printer
How would i send a copy of the form to the printer?
edit: is there a way to resize it to fit the page?
-
Jun 16th, 2004, 11:57 PM
#2
Thread Starter
Lively Member
-
Jun 17th, 2004, 03:57 AM
#3
Hi.
Does this help?
VB Code:
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Private WithEvents pDoc As Printing.PrintDocument
Private bFormImage As Bitmap
Private Sub PrintForm()
bFormImage = Me.GetFormImage
pDoc = New Printing.PrintDocument()
Dim pp As New PrintPreviewDialog()
pp.Document = pDoc
pp.ShowDialog(Me)
End Sub
Private Function GetFormImage() As Bitmap
Dim FW, FH As Integer
Dim hSDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim r As Integer
hSDC = CreateDC("DISPLAY", "", "", "")
hMDC = CreateCompatibleDC(hSDC)
FW = Me.Width
FH = Me.Height
hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
hBMPOld = SelectObject(hMDC, hBMP)
r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, Me.Left, Me.Top, 13369376)
hBMP = SelectObject(hMDC, hBMPOld)
r = DeleteDC(hSDC)
r = DeleteDC(hMDC)
hSDC = Nothing
hMDC = Nothing
r = Nothing
Return Bitmap.FromHbitmap(New IntPtr(hBMP))
DeleteObject(hBMP)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PrintForm()
End Sub
Private Sub pDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pDoc.PrintPage
'Draw Stretched
'e.Graphics.DrawImage(bFormImage, e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
'Draw Normal
e.Graphics.DrawImage(bFormImage, e.MarginBounds.Left, e.MarginBounds.Top, bFormImage.Width, bFormImage.Height)
e.HasMorePages = False
End Sub
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Jun 18th, 2004, 02:47 PM
#4
Thread Starter
Lively Member
i know that there is an easier way to do that... got any idea?
-
Jun 19th, 2004, 08:07 AM
#5
Addicted Member
Hi,
Watch and copy examples of Source Code in VB.NET
http://www.geocities.com/yulyos4vbnet
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|