[英]How to Get File then Print from a Textbox?
I'm programming for a friend to help them print all files in a folder (after filtering them).我正在为一个朋友编程,帮助他们打印文件夹中的所有文件(过滤后)。 I've gotten to the point where I am able to select a folder, filter the files according to extension, and list them in a ListBox.
我已经到了能够 select 一个文件夹、根据扩展名过滤文件并将它们列在列表框中的地步。 I'm thinking that I'm going to have to Loop 1) Get "File1 Name", 2) Print File1, and 3) Go to the next item, Until there are no more files.
我想我将不得不循环 1) 获取“文件 1 名称”,2) 打印文件 1,以及 3) Go 到下一个项目,直到没有更多文件。 So I'm testing it out on just a regular textbox where I input the location of file
"C:\Users\akapp\OneDrive\Documents\AAppleton Midterm.pdf."
所以我只是在一个常规文本框上对其进行测试,我在其中输入文件
"C:\Users\akapp\OneDrive\Documents\AAppleton Midterm.pdf."
Is there a way to do GetFiles and Print after using a button?有没有办法在使用按钮后执行 GetFiles 和 Print?
This is the Print Dialogue I'm using:这是我正在使用的打印对话:
Private Sub BtnPrint_Click(sender As Object, e As RoutedEventArgs) Handles btnPrint.Click
Dim printDoc As New PrintDocument()
Dim printDlg As New PrintDialog With {
.Document = printDoc,
.PrinterSettings = printDoc.PrinterSettings,
.AllowSomePages = True
}
If printDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
printDoc.PrinterSettings = printDlg.PrinterSettings
printDoc.Print()
End If
End Sub
It works fine, but just prints a blank page.它工作正常,但只打印一个空白页。
I've tried printDoc.DocumentName = txtTest.Text
but that does not work... ;-;我试过
printDoc.DocumentName = txtTest.Text
但这不起作用......;-;
Any help is very appreciated.非常感谢任何帮助。 ^u^
^你^
Also I am a very new programmer.我也是一个非常新的程序员。 Like, started this past week with this project.
就像,上周开始这个项目。
Thank you to @jmcilhinney to start me in the right direction of Process.Start!感谢@jmcilhinney 让我朝着 Process.Start 的正确方向开始!
My final code (for printing files from their names in my listbox) is this!我的最终代码(用于从我的列表框中的名称打印文件)是这样的!
Dim psI As Process Start Info
Try
Dim printDlg As PrintDialog
printDlg = New PrintDialog()
If printDlg.ShowDialog = True Then
For i = 0 To lstbxFiles.Items.Count - 1
'psI.Arguments = """" & cmbxPrinters.Text & """"
psI = New ProcessStartInfo(lstbxFiles.Items(i).ToString()) With
{
.Arguments = """" & printDlg.PrintQueue.FullName & """",
.UseShellExecute = True,
.Verb = "PrintTo",
.CreateNoWindow = True,
.WindowStyle = ProcessWindowStyle.Hidden
}
System.Threading.Thread.Sleep(3000)
Process.Start(psI)
Next
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
Hopefully this may help other people!希望这可以帮助其他人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.