• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET PrintDocument.PrinterSettings属性代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Drawing.Printing.PrintDocument.PrinterSettings属性的典型用法代码示例。如果您正苦于以下问题:VB.NET PrintDocument.PrinterSettings属性的具体用法?VB.NET PrintDocument.PrinterSettings怎么用?VB.NET PrintDocument.PrinterSettings使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Drawing.Printing.PrintDocument的用法示例。



在下文中一共展示了PrintDocument.PrinterSettings属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: Printing

Public Sub Printing()
    Try
        streamToPrint = New StreamReader(filePath)
        Try
            printFont = New Font("Arial", 10)
            Dim pd As New PrintDocument()
            AddHandler pd.PrintPage, AddressOf pd_PrintPage
            ' Specify the printer to use.
            pd.PrinterSettings.PrinterName = printer
            pd.Print()
        Finally
               streamToPrint.Close()
        End Try
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub
开发者ID:VB.NET开发者,项目名称:System.Drawing.Printing,代码行数:17,代码来源:PrintDocument.PrinterSettings


示例2: MainClass

' 导入命名空间
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Drawing.Printing


Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New Dialogs()
        Application.Run(myform)
    End Sub

End Class

Public Class Dialogs

    'Declare variable
    Private strFileName As String
    Private objStreamToPrint As StreamReader
    Private objPrintFont As Font

    Private Sub btnOpen_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnOpen.Click

        'Set the Open dialog properties
        With OpenFileDialog1
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .Title = "Demo Open File Dialog"
        End With

        'Show the Open dialog and if the user clicks the Open button,
        'load the file
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim allText As String
            Try
                'Save the file name
                strFileName = OpenFileDialog1.FileName
                'Read the contents of the file
                allText = My.Computer.FileSystem.ReadAllText(strFileName)
                'Display the file contents in the TextBox
                txtFile.Text = allText
            Catch fileException As Exception
                Throw fileException
            End Try
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnSave.Click

        'Set the Save dialog properties
        With SaveFileDialog1
            .DefaultExt = "txt"
            .FileName = strFileName
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .OverwritePrompt = True
            .Title = "Demo Save File Dialog"
        End With

        'Show the Save dialog and if the user clicks the Save button,
        'save the file
        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                'Save the file name
                strFileName = SaveFileDialog1.FileName
                Dim filePath As String
                'Open or Create the file
                filePath = System.IO.Path.Combine( _
                    My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
                    strFileName)
                'Replace the contents of the file
                My.Computer.FileSystem.WriteAllText(filePath, txtFile.Text, False)
            Catch fileException As Exception
                Throw fileException
            End Try
        End If
    End Sub

    Private Sub btnFont_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnFont.Click

        'Set the FontDialog control properties
        FontDialog1.ShowColor = True

        'Show the Font dialog
        If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            'If the OK button was clicked set the font
            'in the text box on the form
            txtFile.Font = FontDialog1.Font
            'Set the color of the font in the text box on the form
            txtFile.ForeColor = FontDialog1.Color
        End If
    End Sub

    Private Sub btnColor_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnColor.Click

        'Show the Color dialog
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            'Set the BackColor property of the form
            Me.BackColor = ColorDialog1.Color
        End If
    End Sub

    Private Sub btnPrint_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnPrint.Click

        'Declare an object for the PrintDocument class
        Dim objPrintDocument As PrintDocument = New PrintDocument()

        'Set the DocumentName property
        objPrintDocument.DocumentName = "Text File Print Demo"

        PrintDialog1.AllowPrintToFile = False
        PrintDialog1.AllowSelection = False
        PrintDialog1.AllowSomePages = False

        PrintDialog1.Document = objPrintDocument

        If PrintDialog1.ShowDialog() = DialogResult.OK Then
            objStreamToPrint = New StreamReader(strFileName)

            objPrintFont = New Font("Arial", 10)

            AddHandler objPrintDocument.PrintPage, _
                AddressOf objPrintDocument_PrintPage

            objPrintDocument.PrinterSettings = PrintDialog1.PrinterSettings

            objPrintDocument.Print()

            objStreamToPrint.Close()
            objStreamToPrint = Nothing
        End If
    End Sub

    Private Sub objPrintDocument_PrintPage(ByVal sender As Object, _
        ByVal e As System.Drawing.Printing.PrintPageEventArgs)

        Dim sngLinesPerpage As Single = 0
        Dim sngVerticalPosition As Single = 0
        Dim intLineCount As Integer = 0
        Dim sngLeftMargin As Single = e.MarginBounds.Left
        Dim sngTopMargin As Single = e.MarginBounds.Top
        Dim strLine As String

        sngLinesPerpage = _
           e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics)

        strLine = objStreamToPrint.ReadLine()

        While (intLineCount < sngLinesPerpage And Not (strLine Is Nothing))

            sngVerticalPosition = sngTopMargin + _
                (intLineCount * objPrintFont.GetHeight(e.Graphics))

            e.Graphics.DrawString(strLine, objPrintFont, Brushes.Black, _
                sngLeftMargin, sngVerticalPosition, New StringFormat())
            intLineCount = intLineCount + 1

            If (intLineCount < sngLinesPerpage) Then
                strLine = objStreamToPrint.ReadLine()
            End If

        End While

        If (strLine <> Nothing) Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnBrowse.Click

        FolderBrowserDialog1.Description = "Select a folder for your backups:"
        FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
        FolderBrowserDialog1.ShowNewFolderButton = False

        If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            'Display the selected folder
            txtFile.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub
End Class



<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public Class Dialogs
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.txtFile = New System.Windows.Forms.TextBox
        Me.btnOpen = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.btnSave = New System.Windows.Forms.Button
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.btnFont = New System.Windows.Forms.Button
        Me.FontDialog1 = New System.Windows.Forms.FontDialog
        Me.btnColor = New System.Windows.Forms.Button
        Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
        Me.btnPrint = New System.Windows.Forms.Button
        Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
        Me.btnBrowse = New System.Windows.Forms.Button
        Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog
        Me.SuspendLayout()
        '
        'txtFile
        '
        Me.txtFile.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtFile.Location = New System.Drawing.Point(8, 8)
        Me.txtFile.Multiline = True
        Me.txtFile.Name = "txtFile"
        Me.txtFile.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtFile.Size = New System.Drawing.Size(352, 264)
        Me.txtFile.TabIndex = 0
        '
        'btnOpen
        '
        Me.btnOpen.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnOpen.Location = New System.Drawing.Point(367, 8)
        Me.btnOpen.Name = "btnOpen"
        Me.btnOpen.Size = New System.Drawing.Size(75, 23)
        Me.btnOpen.TabIndex = 1
        Me.btnOpen.Text = "Open"
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.FileName = "OpenFileDialog1"
        '
        'btnSave
        '
        Me.btnSave.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnSave.Location = New System.Drawing.Point(367, 38)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(75, 23)
        Me.btnSave.TabIndex = 2
        Me.btnSave.Text = "Save"
        '
        'btnFont
        '
        Me.btnFont.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnFont.Location = New System.Drawing.Point(367, 68)
        Me.btnFont.Name = "btnFont"
        Me.btnFont.Size = New System.Drawing.Size(75, 23)
        Me.btnFont.TabIndex = 3
        Me.btnFont.Text = "Font"
        '
        'btnColor
        '
        Me.btnColor.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnColor.Location = New System.Drawing.Point(367, 98)
        Me.btnColor.Name = "btnColor"
        Me.btnColor.Size = New System.Drawing.Size(75, 23)
        Me.btnColor.TabIndex = 4
        Me.btnColor.Text = "Color"
        '
        'btnPrint
        '
        Me.btnPrint.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnPrint.Location = New System.Drawing.Point(367, 128)
        Me.btnPrint.Name = "btnPrint"
        Me.btnPrint.Size = New System.Drawing.Size(75, 23)
        Me.btnPrint.TabIndex = 5
        Me.btnPrint.Text = "Print"
        '
        'btnBrowse
        '
        Me.btnBrowse.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnBrowse.Location = New System.Drawing.Point(367, 158)
        Me.btnBrowse.Name = "btnBrowse"
        Me.btnBrowse.Size = New System.Drawing.Size(75, 23)
        Me.btnBrowse.TabIndex = 6
        Me.btnBrowse.Text = "Browse"
        '
        'FolderBrowserDialog1
        '
        Me.FolderBrowserDialog1.SelectedPath = "FolderBrowserDialog1"
        '
        'Dialogs
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(448, 277)
        Me.Controls.Add(Me.btnBrowse)
        Me.Controls.Add(Me.btnPrint)
        Me.Controls.Add(Me.btnColor)
        Me.Controls.Add(Me.btnFont)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.btnOpen)
        Me.Controls.Add(Me.txtFile)
        Me.Name = "Dialogs"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Dialogs"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents txtFile As System.Windows.Forms.TextBox
    Friend WithEvents btnOpen As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    Friend WithEvents btnFont As System.Windows.Forms.Button
    Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
    Friend WithEvents btnColor As System.Windows.Forms.Button
    Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
    Friend WithEvents btnPrint As System.Windows.Forms.Button
    Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
    Friend WithEvents btnBrowse As System.Windows.Forms.Button
    Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog

End Class
开发者ID:VB程序员,项目名称:System.Drawing.Printing,代码行数:343,代码来源:PrintDocument.PrinterSettings



注:本文中的System.Drawing.Printing.PrintDocument.PrinterSettings属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET PrinterSettings.MaximumCopies属性代码示例发布时间:2022-05-26
下一篇:
VB.NET PrintDocument.PrintController属性代码示例发布时间:2022-05-26
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap