Results 1 to 5 of 5

Thread: Sending document to printer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91

    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?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    bump

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Does this help?

    VB Code:
    1. 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
    2.     Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
    3.     Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
    4.     Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
    5.     Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
    6.     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
    7.     Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
    8.     Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
    9.  
    10.     Private WithEvents pDoc As Printing.PrintDocument
    11.     Private bFormImage As Bitmap
    12.  
    13.     Private Sub PrintForm()
    14.         bFormImage = Me.GetFormImage
    15.         pDoc = New Printing.PrintDocument()
    16.  
    17.         Dim pp As New PrintPreviewDialog()
    18.         pp.Document = pDoc
    19.         pp.ShowDialog(Me)
    20.     End Sub
    21.  
    22.     Private Function GetFormImage() As Bitmap
    23.         Dim FW, FH As Integer
    24.         Dim hSDC, hMDC As Integer
    25.         Dim hBMP, hBMPOld As Integer
    26.         Dim r As Integer
    27.  
    28.         hSDC = CreateDC("DISPLAY", "", "", "")
    29.         hMDC = CreateCompatibleDC(hSDC)
    30.  
    31.         FW = Me.Width
    32.         FH = Me.Height
    33.  
    34.         hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
    35.  
    36.         hBMPOld = SelectObject(hMDC, hBMP)
    37.         r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, Me.Left, Me.Top, 13369376)
    38.         hBMP = SelectObject(hMDC, hBMPOld)
    39.  
    40.         r = DeleteDC(hSDC)
    41.         r = DeleteDC(hMDC)
    42.  
    43.         hSDC = Nothing
    44.         hMDC = Nothing
    45.         r = Nothing
    46.  
    47.         Return Bitmap.FromHbitmap(New IntPtr(hBMP))
    48.         DeleteObject(hBMP)
    49.  
    50.  
    51.     End Function
    52.  
    53.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    54.         Me.PrintForm()
    55.     End Sub
    56.  
    57.     Private Sub pDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pDoc.PrintPage
    58.         'Draw Stretched
    59.         'e.Graphics.DrawImage(bFormImage, e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
    60.  
    61.         'Draw Normal
    62.         e.Graphics.DrawImage(bFormImage, e.MarginBounds.Left, e.MarginBounds.Top, bFormImage.Width, bFormImage.Height)
    63.  
    64.         e.HasMorePages = False
    65.     End Sub
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    i know that there is an easier way to do that... got any idea?

  5. #5
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224
    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
  •  



Click Here to Expand Forum to Full Width