Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用vb.net 2010显示打印机窗口_Vb.net - Fatal编程技术网

如何使用vb.net 2010显示打印机窗口

如何使用vb.net 2010显示打印机窗口,vb.net,Vb.net,您好,我有这个代码将我的面板发送到打印机,但问题是它没有发送让我选择我将使用哪台打印机关于如何使打印机窗口出现的任何想法? 谢谢 公共类表单1 将img设置为位图 将事件pd作为打印文档进行Dim '将窗体作为位图返回 函数CaptureForm1()作为位图 Dim g1 As Graphics=Me.CreateGraphics() Dim MyImage=新位图(Me.ClientRectangle.Width,(Me.ClientRectangle.Height),g1) 将g2尺寸调整

您好,我有这个代码将我的面板发送到打印机,但问题是它没有发送让我选择我将使用哪台打印机关于如何使打印机窗口出现的任何想法? 谢谢

公共类表单1
将img设置为位图
将事件pd作为打印文档进行Dim
'将窗体作为位图返回
函数CaptureForm1()作为位图
Dim g1 As Graphics=Me.CreateGraphics()
Dim MyImage=新位图(Me.ClientRectangle.Width,(Me.ClientRectangle.Height),g1)
将g2尺寸调整为Graphics=Graphics.FromImage(MyImage)
作为IntPtr=g1.GetHdc()的Dim dc1
作为IntPtr=g2.GetHdc()的Dim dc2
BitBlt(dc2,0,0,Me.ClientRectangle.Width,(Me.ClientRectangle.Height),dc1,0,0,13369376)
g1.释放HDC(dc1)
g2.释放HDC(dc2)
'只需将图像保存到c驱动器,您也可以对其进行注释
'MyImage.Save(“c:\abc.bmp”)
返回我的图像
端函数
_
专用共享函数BitBlt(ByVal hdcDest作为IntPtr,ByVal nXDest作为Integer,ByVal nYDest作为Integer,ByVal nWidth作为Integer,ByVal nHeight作为Integer,ByVal hdcSrc作为IntPtr,ByVal nXSrc作为Integer,ByVal nyrc作为Integer,ByVal dwRop作为System.Int32)作为布尔值
'将函数留空-DLLImport属性将对MoveFile的调用转发给
'MoveFileW在KERNEL32.DLL中。
端函数
私有子按钮1\u单击(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理按钮1。单击
img=CaptureForm1()
pd=新打印文档
pd.Print()
端接头
'每次发生pd.printpage事件时都将调用此方法
子pd_PrintPage(ByVal发送方作为对象,ByVal e作为PrintPageEventArgs)处理pd.PrintPage
尺寸x为整数=e.MarginBounds.x
尺寸y为整数=e.MarginBounds.y
e、 图形.绘图图像(img,x,y)
e、 HasMorePages=False
端接头
末级

wow谢谢它工作得很好,但我还有一个问题,不是将输出发送到打印机,而是如何将其转换为PDF格式??作为新问题提问。嗨,我只是作为新问题提问希望你能帮助我谢谢
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