打印列表框项目按出现顺序排列 [英] Printing listbox Items in order of occurence

查看:60
本文介绍了打印列表框项目按出现顺序排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个我已经建立的应用程序和

只是打印c#App,

首先我填充ListBox并格式化然后转到c :\ somefolder
某些文件夹中的
是在列表框中查找的pdf文件,看看是否有任何文件名与列表框中的项目匹配,并将其发送到默认打印机。

一切都很好,但是说我有JohnDoe.pdf,ShahRukh.pdf,Vijay.pdf

如何让它按顺序发送文件,现在它工作得很好,但我希望能够打印==>首先是JohnDoe.pdf,然后是ShahRukg.pdf,依旧等等。如果你有任何想法可以放心,欢迎光临。

谢谢你。

Hi guys, Please I have an application that I have built and
is just sort of printing c# App,
First I populate ListBox and format it then goto c:\somefolder
in some folder are pdf files it looks on listbox and see if there is any file name that matches an item on the listbox and sends it to the default printer.
Everything is working great ,but say I have JohnDoe.pdf,ShahRukh.pdf,Vijay.pdf
how can I make it to send the files in that order, for now it works greatt ,but I want to be able to print ==> JohnDoe.pdf first, then ShahRukg.pdf and so on and so forth.Please if you have any idea to spare is much welcome.
Thanks in adavance.

推荐答案

private void btn_PrintMacro_Click(object sender, EventArgs e)
       {
          try
          {
               string dir = @"C:\slim\slimyyyy"

               if (Directory.Exists(dir))//If a directory defined above exists then do the followings
               {
                   string[] pdf_specFiles = Directory.GetFiles(dir);
                   if (pdf_specFiles.Length > 0)
                   {

                    //   foreach (string file in pdf_specFiles)
                       //{
                       //    string fileName = Path.GetFileName(file);
                           foreach (object item in listBox1.Items)
                         //  foreach (object line in rchTxtContent.Lines)
                           {
                               foreach (string file in pdf_specFiles)
                               {
                                   string fileName = Path.GetFileName(file);
                               if (fileName == item.ToString())

                               {
                                   PrintDocument(Path.GetFullPath(file));
                               }

                           }
                       }
                   }
               }
           }
           catch (Exception  )
           {
               MessageBox.Show("There is a possibility that one or more  of  Spec file - (s)  is not in the said Directory ok.");
           }
       }


   {

    var printList = new List();

    try
    {
        string dir = @"C:\slim\slimyyyy";
        if (Directory.Exists(dir))
        {
            string[] pdf_specFiles = Directory.GetFiles(dir);
            if (pdf_specFiles.Length > 0)
            {
                foreach (object item in listBox1.Items)
                {
                    foreach (string file in pdf_specFiles)
                    {
                        string fileName = Path.GetFileName(file);
                        if (fileName == item.ToString())
                        {
                            printList.Add(Path.GetFullPath(file));
                        }
                    }
                }

                foreach (string file in printList)
                {
                    PrintDocument(file);
                    System.Threading.Thread.Sleep(10000); // wait half a second say
                    Application.DoEvents(); // keep UI responsive if Windows Forms app
                }
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("" + ex);
    }
}>


这篇关于打印列表框项目按出现顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆