how to make the printer window appear using vb.net 2010

Posted by Jeline Esase on Stack Overflow See other posts from Stack Overflow or by Jeline Esase
Published on 2013-11-04T03:49:10Z Indexed on 2013/11/04 3:53 UTC
Read the original article Hit count: 244

Filed under:

hi I have this code that will send my panel into a printer but the problem is it doesent let me choose which printer I will use any idea on how can I make the printer window appear? thanks

Public Class Form1

Dim img As Bitmap
Dim WithEvents pd As PrintDocument

'Returns the Form as a bitmap
Function CaptureForm1() As Bitmap

    Dim g1 As Graphics = Me.CreateGraphics()
    Dim MyImage = New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1)
    Dim g2 As Graphics = Graphics.FromImage(MyImage)
    Dim dc1 As IntPtr = g1.GetHdc()
    Dim dc2 As IntPtr = g2.GetHdc()
    BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376)
    g1.ReleaseHdc(dc1)
    g2.ReleaseHdc(dc2)
    'saves image to c drive just, u can comment it also
    'MyImage.Save("c:\abc.bmp")
    Return MyImage
End Function

<DllImport("gdi32.DLL", EntryPoint:="BitBlt", _
 SetLastError:=True, CharSet:=CharSet.Unicode, _
 ExactSpelling:=True, _
 CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean

    ' Leave function empty - DLLImport attribute forwards calls to MoveFile to
    ' MoveFileW in KERNEL32.DLL.
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    img = CaptureForm1()
    pd = New PrintDocument
    pd.Print()

End Sub
'this method will be called each time when pd.printpage event occurs
Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage

    Dim x As Integer = e.MarginBounds.X
    Dim y As Integer = e.MarginBounds.Y
    e.Graphics.DrawImage(img, x, y)
    e.HasMorePages = False

End Sub

End Class

© Stack Overflow or respective owner

Related posts about vb.net