设置后 VB .NET WinFormApplication 打印失败横向模式

Posted

技术标签:

【中文标题】设置后 VB .NET WinFormApplication 打印失败横向模式【英文标题】:VB .NET WinFormApplication Printing Failed Landscape mode after setting 【发布时间】:2013-07-18 08:51:47 【问题描述】:

我正在使用 VB .NET 编程,我想在横向模式下打印我的WinFormsApplication,因为纵向模式不适合它。

我已将横向模式设置为 true。你可以参考下面的代码:

    Private Sub PrintAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    Handles PrintAll.Click
    PrintForm1.Form = Me
    PrintDocument1.DefaultPageSettings.Landscape = True
    PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)
    PrintDialog1.ShowDialog()
    End Sub

结果如下截图所示 http://s335.photobucket.com/user/blakeex/media/notcomplete.png.html 谁能分享一些提示或指南?

【问题讨论】:

【参考方案1】:

to print the complete client area of a scrollable form, even if the form has been resized.

试试PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)

这是另一种打印屏幕上可以查看的表单部分的方法:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    CaptureScreen()
    PrintDocument1.DefaultPageSettings.Landscape = True
    PrintDocument1.DefaultPageSettings.Margins = New Printing.Margins(0, 0, 0, 0)
    PrintDocument1.Print()
End Sub
Dim memoryImage As Bitmap
Private Sub CaptureScreen()
    Dim myGraphics As Graphics = Me.CreateGraphics()
    Dim s As Size = Me.Size
    memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
    Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
    memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub
Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim pagerec As New RectangleF(e.PageSettings.PrintableArea.X, e.PageSettings.PrintableArea.Y, e.PageSettings.PrintableArea.Height, e.PageSettings.PrintableArea.Width)
    e.Graphics.DrawImage(memoryImage, pagerec, New Rectangle(Me.Location, Me.Size), GraphicsUnit.Pixel)
End Sub

【讨论】:

亲爱的@tinstaafl 和其他尊敬的成员,我已经尝试过你上面的方法。它无法正常工作,如下面的截图网站所示:[s335.photobucket.com/user/blakeex/media/notcomplete-1.png.html]您能否提出替代方案或我错过了一步? 我添加了替代答案。

以上是关于设置后 VB .NET WinFormApplication 打印失败横向模式的主要内容,如果未能解决你的问题,请参考以下文章

vb.net怎么设置数字保留小数点位数

VB.NET 错误中断问题

C#/VB.NET 将文本内容更改为大写

PDF 生成后无法打开 (vb.net) (asp.net)

在VB.net里调用excel程序的时候的几个问题

vb.net动态设置gridview列的属性