C# 批量打印

  • Post author:
  • Post category:其他


软件介绍:

批量打印软件能够将用户所选择指定文件夹内所有文件(不含子文件夹)全部遍历打印。点击打印按钮后,系统会自动调用与此电脑连接的打印机,打印操作在后台执行

软件源代码:

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e) //浏览所需打印路径
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = dialog.SelectedPath;
            } 
        }

        private void button1_Click(object sender, EventArgs e)  //批量打印
        {
            if (textBox1.Text=="")
            {
                MessageBox.Show("请选择打印文件路径");
                return;
            }
            string[] path_Name = GetFilePath(textBox1.Text);
            for (int i = 0; i < path_Name.Length; i++)
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.FileName = path_Name[i];
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.StartInfo.Verb = "Print";
                process.Start();
            }
        }

        private string[] GetFilePath(string text) //遍历用户所选文件夹下文件
        {
            if (Directory.Exists(text))
            {
                string[] dir = Directory.GetFiles(text);
                string[] names = new string[dir.Length];
                for (int i = 0; i < dir.Length; i++)
                {
                    //  names[i] = Path.GetFileName(dir[i]);
                    names[i] = Path.GetFullPath(dir[i]);
                }
                return names;
            }
            else
            {
                return null;
            }
        }
    }

软件运行效果:



版权声明:本文为m0_47020592原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。