我正在尝试从PrintDialog获取用户选择的打印机名称,但是PrintDialog1.PrinterSettings.PrinterName.Equals返回默认的Windows打印机名称,而不是在对话框中选择的打印机,是否有任何线索?
Dim userResp As DialogResult = PrintDialog1.ShowDialog()
PrintDialog1.Document = PreparePrintDocument()
If userResp = DialogResult.OK Then
If PrintDialog1.PrinterSettings.PrinterName.Equals("Microsoft Print to PDF") Then
do something
Else
do something else
End If
在此示例中,在对话框中按“ Microsoft Print to PDF”后,调试状态为Windows默认打印机“ Canon xxx”。
还有另一种方法可以在对话框中选择打印机吗? 文档说明PrinterSettings.PrinterName可以获取或设置值吗?
答案 0 :(得分:1)
简单错误。在ShowDialog()之前添加此行即可解决此问题!
char[] charray = inputstring.toCharArray();
List<string> deuces= new List<string>();
for(int i=0;i<charray.length;i++){
string holder = charray[i]+charray[i+1];
deuces.Add(holder)
}
答案 1 :(得分:0)
我们只是比较字符串,所以=运算符就可以。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If PrintDialog1.ShowDialog() = DialogResult.OK Then
'Just to check what they chose.
Debug.Print(PrintDialog1.PrinterSettings.PrinterName)
If PrintDialog1.PrinterSettings.PrinterName = "Microsoft Print to PDF" Then
MessageBox.Show("Your chose PDf.")
End If
End If
End Sub
实际上,您的代码也对我有用。
If PrintDialog1.PrinterSettings.PrinterName.Equals("Microsoft Print to PDF") Then