最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#調(diào)用打印機實現(xiàn)打印

 更新時間:2022年04月29日 11:41:33   作者:農(nóng)碼一生  
這篇文章介紹了C#調(diào)用打印機實現(xiàn)打印的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

一、引用BarcodeStandard.dll

        #region BarcodeStandard.dll
        /*
         * 
         * 使用說明
         需要通過NuGet進行安裝BarcodeLib.dll,必不可少
         */

        string inputString;

        /// <summary>
        /// 獲取所以打印機驅(qū)動名稱
        /// </summary>
        private void getPrintDocumentlist()
        {
            PrintDocument print = new PrintDocument();
            string sDefault = print.PrinterSettings.PrinterName;//默認(rèn)打印機名
            comboBox_drive.Items.Add(sDefault);

            comboBox_drive.Text = sDefault;//顯示默認(rèn)驅(qū)動名稱
            foreach (string sPrint in PrinterSettings.InstalledPrinters)//獲取所有打印機名稱
            {
                if (sPrint != sDefault)
                {
                    comboBox_drive.Items.Add(sPrint);
                }
            }

        }
        /// <summary>
        /// 打印繪制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Font titleFont = new Font("宋體", 9, FontStyle.Bold);//標(biāo)題字體           

            Font fntTxt = new Font("宋體", 9, FontStyle.Regular);//正文文字           

            Brush brush = new SolidBrush(Color.Black);//畫刷           

            Pen pen = new Pen(Color.Black); //線條顏色           

            Point po = new Point(10, 10);
            try
            {
                //畫String
                e.Graphics.DrawString(GetPrintSW().ToString(), titleFont, brush, po);//打印內(nèi)容
             
                
                //畫橫線
                //Point[] point = { new Point(20, 50), new Point(200, 50) };//縱坐標(biāo)不變
                //e.Graphics.DrawLines(pen, point);
                //畫豎線
                //Point[] points1 = { new Point(60, 70), new Point(60, 70 + 40) };//橫坐標(biāo)不變
                //e.Graphics.DrawLines(pen, points1);
                //畫矩形
                //e.Graphics.DrawRectangle(pen, 20, 70, 90, 90);
            }

            catch (Exception ex)
            {
                MessageBox.Show(this, "打印出錯!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
       /// <summary>
       /// 獲取打印內(nèi)容
       /// </summary>
       /// <returns></returns>
        public StringBuilder GetPrintSW()
        {
            StringBuilder sb = new StringBuilder();

            string tou = "XXXXXX科技有限公司";

            string address = "安徽省合肥市瑤海區(qū)";

            string saleID = "100010000001";    //單號       

            string item = "項目";

            decimal price = 25.00M;

            int count = 5;

            decimal total = 0.00M;

            decimal fukuan = 500.00M;

            sb.AppendLine(" " + tou + " \n");

            sb.AppendLine("-----------------------------------------");

            sb.AppendLine("日期:" + DateTime.Now.ToShortDateString() + " " + "單號:" + saleID);

            sb.AppendLine("-----------------------------------------");

            sb.AppendLine("項目" + "    " + "數(shù)量" + "  " + "單價" + "    " + "小計");

            for (int i = 0; i < count; i++)
            {
                decimal xiaoji = (i + 1) * price;

                sb.AppendLine(item + (i + 1) + "    " + (i + 1) + "   " + price + "    " + xiaoji);

                total += xiaoji;

            }

            sb.AppendLine("-----------------------------------------");

            sb.AppendLine("數(shù)量:" + count + "  合計: " + total);

            sb.AppendLine("付款:" + fukuan);

            sb.AppendLine("現(xiàn)金找零:" + (fukuan - total));

            sb.AppendLine("-----------------------------------------");

            sb.AppendLine("地址:" + address + "");

            sb.AppendLine("電話:130000000000");

            sb.AppendLine("謝謝惠顧歡迎下次光臨!");

            sb.AppendLine("-----------------------------------------");

            return sb;

        }


        /// <summary>
        /// 生成條形碼
        /// </summary>
        /// <param name="content">內(nèi)容</param>
        /// <returns></returns>
        public static Image GenerateBarCodeBitmap(string content)
        {
            using (var barcode = new Barcode()
            {
                IncludeLabel = true,
                Alignment = AlignmentPositions.CENTER,
                Width = 250,
                Height = 100,
                RotateFlipType = RotateFlipType.RotateNoneFlipNone,
                BackColor = Color.White,
                ForeColor = Color.Black,
            })
            {
                return barcode.Encode(TYPE.CODE128B, content);
            }
        }
        #endregion

二、引用Seagull.BarTender.Print.dll

        #region   Seagull.BarTender.Print.dll
        /// <summary>
        /// 打印測試
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printbt_Click(object sender, EventArgs e)
        {
            string qd = comboBox_drive.Text;//下拉列表選擇的驅(qū)動名稱
            var printDocument = new PrintDocument();
            //指定打印機
            printDocument.PrinterSettings.PrinterName = qd;//驅(qū)動名稱             

            printDocument.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
            try
            {
               
                //打印預(yù)覽
                //PrintPreviewDialog ppd = new PrintPreviewDialog();
                //ppd.Document = printDocument;
                //ppd.ShowDialog();

                //打印
                printDocument.Print();
            }
            catch (InvalidPrinterException)
            {

            }
            finally
            {
                printDocument.Dispose();
            }
        }
        /// <summary>
        /// BarTender打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BarTender_Click(object sender, EventArgs e)
        {
            try

            {
                //程序中寫入引用 using Seagull.BarTender.Print.dll,必不可少;
                //安裝Bartender后,在安裝的根目錄或者system32下課可找到對應(yīng)的dll
                #region 
                Engine btEngine = new Engine();
                btEngine.Start();
                string lj = AppDomain.CurrentDomain.BaseDirectory + "test.btw";  //test.btw是BT的模板
                LabelFormatDocument btFormat = btEngine.Documents.Open(lj);

                //對BTW模版相應(yīng)字段進行賦值 
                btFormat.SubStrings["name"].Value ="Liming";
                btFormat.SubStrings["code"].Value = "1234567890";

                //指定打印機名 
                btFormat.PrintSetup.PrinterName = "WPS 虛擬打印機";

                //改變標(biāo)簽打印數(shù)份連載 
                btFormat.PrintSetup.NumberOfSerializedLabels = 1;

                //打印份數(shù)                   
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                Messages messages;

                int waitout = 10000; // 10秒 超時 
                Result nResult1 = btFormat.Print("標(biāo)簽打印軟件", waitout, out messages);
                btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession;

                //不保存對打開模板的修改 
                btFormat.Close(Seagull.BarTender.Print.SaveOptions.DoNotSaveChanges);

                //結(jié)束打印引擎                  
                btEngine.Stop();
                #endregion


            }
            catch (Exception ex)
            {
                MessageBox.Show("錯誤信息: " + ex.Message);
                return;
            }
        }

        #endregion

三、引用 Interop.LabelManager2.dll

        #region  Interop.LabelManager2.dll
        /// <summary>
        /// 打印功能 CodeSoft
        /// </summary>
        /// <param name="PrintParam1">打印模板參數(shù)值1</param>
        /// <param name="PrintParam2">打印模板參數(shù)值2</param>
        /// <param name="PrintParam3">打印模板參數(shù)值3</param>
        /// <param name="PrintParam4">打印模板參數(shù)值4</param>
        /// <returns></returns>
        public bool SoftCodePrint(string PrintParam1 = "", string PrintParam2 = "", string PrintParam3 = "", string PrintParam4 = "")
        {
            bool result = false;
            int printNum = 2;//打印份數(shù)
            try
            {
                string text = string.Empty;
                ApplicationClass labApp = null;
                Document doc = null;
                string labFileName = AppDomain.CurrentDomain.BaseDirectory + "Template\\" + "Test.Lab";//模板地址
                if (!File.Exists(labFileName))
                {
                    throw new Exception("沒有找到標(biāo)簽?zāi)0?);
                }

                for (int i = 0; i < printNum; i++)
                {
                    labApp = new ApplicationClass();
                    labApp.Documents.Open(labFileName, false);// 調(diào)用設(shè)計好的label文件
                    doc = labApp.ActiveDocument;

                    //可通過配置檔進行配置打印信息
                    doc.Variables.FreeVariables.Item("模板變量名稱1").Value = PrintParam1;
                    doc.Variables.FreeVariables.Item("模板變量名稱2").Value = PrintParam2;
                    doc.Variables.FreeVariables.Item("模板變量名稱3").Value = PrintParam3;
                    doc.Variables.FreeVariables.Item("模板變量名稱4").Value = PrintParam4;
                    doc.PrintDocument(1);
                }

                labApp.Quit();
                result = true;
            }
            catch (Exception ex)
            {

            }
            return result;

        }
        #endregion

dll下載地址

到此這篇關(guān)于C#調(diào)用打印機實現(xiàn)打印的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#中Override關(guān)鍵字和New關(guān)鍵字的用法詳解

    C#中Override關(guān)鍵字和New關(guān)鍵字的用法詳解

    這篇文章主要介紹了C#中Override關(guān)鍵字和New關(guān)鍵字的用法,需要的朋友可以參考下
    2016-01-01
  • C#集合之列表的用法

    C#集合之列表的用法

    這篇文章介紹了C#集合之列表的用法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • C#?System.Linq提供類似SQL語法的高效查詢操作

    C#?System.Linq提供類似SQL語法的高效查詢操作

    System.Linq是C#的一個命名空間,提供了LINQ(語言集成查詢)功能,允許開發(fā)者使用一致的查詢語法來處理不同類型的數(shù)據(jù)源,如數(shù)組、集合、數(shù)據(jù)庫和XML等,本文介紹C#?System.Linq提供類似SQL語法的高效查詢操作,感興趣的朋友一起看看吧
    2024-09-09
  • C#集合本質(zhì)之鏈表的用法詳解

    C#集合本質(zhì)之鏈表的用法詳解

    本文詳細講解了C#集合本質(zhì)之鏈表的用法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • C# 禁用鼠標(biāo)中間鍵的方法

    C# 禁用鼠標(biāo)中間鍵的方法

    關(guān)于?。? System.Windows.Forms.NumericUpDown 控件,如何禁用鼠標(biāo)中間鍵?
    2013-03-03
  • .Net6開發(fā)winform程序使用依賴注入

    .Net6開發(fā)winform程序使用依賴注入

    本文詳細講解了.Net6開發(fā)winform程序使用依賴注入的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-12-12
  • C#自定義控件添加右鍵菜單的方法

    C#自定義控件添加右鍵菜單的方法

    這篇文章主要介紹了C#自定義控件添加右鍵菜單的方法,本文用到control控件,專門自定義右鍵菜單,下面小編給大家整理下,有需要的小伙伴可以來參考下
    2015-08-08
  • WPF程序?qū)⒖丶尸F(xiàn)的內(nèi)容保存成圖像

    WPF程序?qū)⒖丶尸F(xiàn)的內(nèi)容保存成圖像

    這篇文章介紹了WPF程序?qū)⒖丶尸F(xiàn)的內(nèi)容保存成圖像的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • C#并發(fā)編程之Task類詳解

    C#并發(fā)編程之Task類詳解

    Task是建立在線程池之上的一種多線程技術(shù),它的出現(xiàn)使Thread成為歷史。其使用方法非常簡單,本文就來通過幾個示例為大家講講它的具體使用吧
    2023-03-03
  • Treeview動態(tài)添加用戶控件傳值和取值的實例代碼

    Treeview動態(tài)添加用戶控件傳值和取值的實例代碼

    今天做了很好玩的樹,是treeview與用戶控件之間進行交互先看效果:
    2013-04-04

最新評論

金昌市| 西吉县| 新河县| 华坪县| 东宁县| 日喀则市| 郓城县| 大化| 东丰县| 那曲县| 灵石县| 喀喇| 东海县| 会昌县| 南涧| 莎车县| 如皋市| 新营市| 武穴市| 云林县| 新宾| 宿迁市| 阳春市| 辽宁省| 漳州市| 邓州市| 喜德县| 金门县| 旅游| 昌都县| 建始县| 怀柔区| 克拉玛依市| 武川县| 万源市| 温泉县| 镇雄县| 定日县| 龙海市| 丘北县| 诸城市|