2015-06-04 18 views
0

大家好日子。我在滚动面板中打印图像时遇到问题。谁能帮我这个?印刷滚动面板与图像里面在vb

我想第一调整图像,显示它在打印预览然后打印

在我的情况之前(因此它可以适应8.5×11" 纸),我有一个窗体(Form)用面板(基座=填充),我想打印里面的图像(2个图像)。但是,图像的打印的触发是在接下来的形式

在btnnext(form1中) Form2.Show() 我.Hide()

and the printing code is in the form2。我是vb中的新手,我对打印scroll没有任何意见能够面板。我在其他论坛尝试了不同的代码,但它没有打印整个图像,而是只显示了窗体的截图。 。任何反应可以理解的,太感谢你了


Public Class Form2 

Private WithEvents pd As New Printing.PrintDocument 
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 
    Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height) 
     Form1.panel1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height)) 
     e.Graphics.DrawImage(bmp, e.MarginBounds) 
    End Using 
End Sub 
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    PrintDocument1.Print() 
End Sub 
End Class 

- ^只打印你可以在屏幕上看到。而不是整个面板..

+0

你使用'panel.DrawToBitmap()'? –

+0

使用bmp作为新的位图(Form1.pb1.Width,Form1.pb1.Height) Form1.pb1.DrawToBitmap(bmp,New Rectangle(0,0,Form1.pb1.Width,Form1.pb1.Height)) e .Graphics.DrawImage(bmp,e.MarginBounds) End使用(我使用此代码,它的工作)现在唯一的问题是打印预览...我不知道在打印预览.. – user4945412

+0

'DrawToBitmap'总是截图因此面板只能拾取可见的内容。这个问题之前在这里提出:http://stackoverflow.com/questions/22056099/with-vb-net-has-anyone-figured-out-a-way-to-print-an-entire-scrollable-form?rq = 1然而,它从来没有回答过 –

回答

-1

基本上,把一切都相同,但不是全页上打印整个第一图像,并打印所述第二图像以它的位置和大小的相对的比例向MarginBounds

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 
    Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height) 
     Form1.pb1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height)) 
     'Print pb1 to fill the whole page 
     e.Graphics.DrawImage(bmp, e.MarginBounds) 
    End Using 
    Using bmp2 As New Bitmap(Form1.pb2.Width, Form1.pb2.Height) 
     Form1.pb2.DrawToBitmap(bmp2, New Rectangle(0, 0, Form1.pb2.Width, Form1.pb2.Height)) 

     Dim x as Double = Form1.pb2.Location.X - Form1.pb1.Location.X 
     x = x * e.MarginBounds.Width/Form1.pb1.Width 
     x = x + e.MarginBounds.X 

     Dim y as Double = Form1.pb2.Location.Y - Form1.pb1.Location.Y 
     y = y * e.MarginBounds.Height/Form1.pb1.Height 
     y = y + e.MarginBounds.Y 

     Dim width as Double = Form1.pb2.width 
     width = width * e.MarginBounds.Width/Form1.pb1.Width 

     Dim height as Double = Form1.pb2.Height 
     height = height * e.MarginBounds.Height/Form1.pb1.Height 

     e.Graphics.DrawImage(bmp2, New Rectangle(x, y, width, height)) 
    End Using 
End Sub 
+0

为什么你会低调而不给出解释为什么? –

+0

但我没有downvoted呢?无论如何,它显示第二个图像,但问题是它显示图像的实际大小(没有找到第一个图像的右侧部分,或者它没有显示面板中显示的内容),而第一个图像被拉伸。 – user4945412

+0

不,我知道这不是你:)我指的是谁做downvote ......无论如何,尝试和两条线'e.Graphics.DrawImage'一起玩,因为它们控制着两个图像的比例。我已经设置了它:第一张图片:从左上角开始,最多为页面的一半,第二张从页面的右侧到最右侧 –