16,555
社区成员
发帖
与我相关
我的任务
分享
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' Add list of supported paper sizes found on the printer.
' The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName"
Dim pkSize As PaperSize
comboPaperSize.Items.Clear()
For i As Integer = 0 To printDoc.PrinterSettings.PaperSizes.Count - 1
pkSize = printDoc.PrinterSettings.PaperSizes.Item(i)
comboPaperSize.Items.Add(pkSize)
Next
' Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
Dim pkCustomSize1 As _
New PaperSize("My Custom Paper Size", CInt(TextBox1.Text), CInt(TextBox2.Text))
comboPaperSize.Items.Add(pkCustomSize1)
comboPaperSize.SelectedIndex = 0
' Add list of paper sources found on the printer to the combo box.
' The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSource.DisplayMember = "SourceName"
Dim pkSource As PaperSource
comboPaperSource.Items.Clear()
For i As Integer = 0 To printDoc.PrinterSettings.PaperSources.Count - 1
pkSource = printDoc.PrinterSettings.PaperSources.Item(i)
comboPaperSource.Items.Add(pkSource.SourceName)
Next
comboPaperSource.SelectedIndex = 0
' Add list of printer resolutions found on the printer to the combobox.
' The PrinterResolution's ToString() method will be used to provide the display string.
'Dim pkResolution As PrinterResolution
'comboPrintResolution.Items.Clear()
'For i As Integer = 0 To printDoc.PrinterSettings.PrinterResolutions.Count - 1
' pkResolution = printDoc.PrinterSettings.PrinterResolutions.Item(i)
' comboPrintResolution.Items.Add(pkResolution.ToString)
'Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' Set the paper size based upon the selection in the combo box
Dim iSelIdx As Integer = comboPaperSize.SelectedIndex
If iSelIdx <> -1 Then
If iSelIdx = printDoc.PrinterSettings.PaperSizes.Count Then
printDoc.DefaultPageSettings.PaperSize = _
New PaperSize("My Custom Paper Size", CInt(TextBox1.Text), CInt(TextBox2.Text))
Else
printDoc.DefaultPageSettings.PaperSize = _
printDoc.PrinterSettings.PaperSizes.Item(comboPaperSize.SelectedIndex)
End If
End If
' Set the paper source based upon the selection in the combo box.
If comboPaperSource.SelectedIndex <> -1 Then
printDoc.DefaultPageSettings.PaperSource = _
printDoc.PrinterSettings.PaperSources.Item(comboPaperSource.SelectedIndex)
End If
' Set the printer resolution based upon the selection in the combo box.
'If comboPrintResolution.SelectedIndex <> -1 Then
' printDoc.DefaultPageSettings.PrinterResolution = _
' printDoc.PrinterSettings.PrinterResolutions.Item(comboPrintResolution.SelectedIndex)
'End If
' Print the document with the specified paper size and source.
printDoc.Print()
End Sub