• 大小: 823KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: C#  打印机  VS2015  

资源简介

一台电脑控制两台打印机同时打印 Font font = new Font("宋体", 9, FontStyle.Bold); Brush bru = Brushes.Blue; e.Graphics.DrawString(textBox1.Text, font, bru, 2, 2);

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PrintTest
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            this.printDocument1.OriginAtMargins = true;//启用页边距
            this.pageSetupDialog1.EnableMetric = true; //以毫米为单位
            foreach (string iprt in PrinterSettings.InstalledPrinters)
                this.comboBox1.Items.Add(iprt);
            textBox1.Text = comboBox1.SelectedText;
            textBox1.AppendText(““);
        }

        //设置打印机
        private void button1_Click(object sender EventArgs e)
        {
            pageSetupDialog1.ShowDialog();
        }
        //打印
        private void button3_Click(object sender EventArgs e)
        {
            printDocument1.PrinterSettings.PrinterName = textBox3.Text;
            printDocument1.Print();

            printDocument2.PrinterSettings.PrinterName = textBox4.Text;
            printDocument2.Print();
        }

        string zhuohao = “K2“;
        string payType = “微信“;
        string payState = “已支付“;
        string dingdan = “888888“;
        string time = DateTime.Now.ToString();
        private void Form1_Load(object sender EventArgs e)
        {
            textBox1.Text = “        测试场景         “
                + “\n“ + “桌号:“ + zhuohao + “\n“
                + “\n“ + “支付方式:“ + payType + “\n“
                + “\n“ + “支付状态:“ + payState + “\n“
                + “\n“ + “订单号:“ + dingdan + “\n“
                + “\n“ + “下单时间:“ + time + “\n“
                + “--------------------------“ + “\n“
                + “商品名称    数量   小计(元)“ + “\n“
                + “--------------------------“ + “\n“
                + “丹麦威士忌   1     ¥0.02   “ + “\n“
                + “--------------------------“ + “\n“
                + “   合计      1     ¥0.02 “ + “\n“
                + “--------------------------“ + “\n“;
        }

        private void printDocument1_PrintPage(object sender System.Drawing.Printing.PrintPageEventArgs e)
        {
            Print(e);
        }

        private void printDocument2_PrintPage(object sender PrintPageEventArgs e)
        {
            Print(e);
        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {
            //textBox3.Text = comboBox1.Text;
            //textBox3.ReadOnly = true;
        }

        //设置打印机
        private void button4_Click(object sender EventArgs e)
        {
            pageSetupDialog2.ShowDialog();
        }

        private void Print(PrintPageEventArgs e)
        {
            Font font = new Font(“宋体“ 9 Fontstyle.Bold);
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-20 15:52  PrintTest\
     目录           0  2017-09-20 15:52  PrintTest\.vs\
     目录           0  2017-09-20 15:52  PrintTest\.vs\PrintTest\
     目录           0  2017-09-20 15:52  PrintTest\.vs\PrintTest\v14\
     文件       24064  2017-09-26 14:19  PrintTest\.vs\PrintTest\v14\.suo
     目录           0  2017-09-26 14:19  PrintTest\PrintTest\
     文件         189  2017-09-20 15:52  PrintTest\PrintTest\App.config
     文件        9831  2017-09-26 14:18  PrintTest\PrintTest\Form1.Designer.cs
     文件        3280  2017-09-26 14:19  PrintTest\PrintTest\Form1.cs
     文件       22552  2017-09-26 14:18  PrintTest\PrintTest\Form1.resx
     文件        5480  2017-09-26 14:18  PrintTest\PrintTest\PrintTest.csproj
     文件         453  2017-09-20 17:31  PrintTest\PrintTest\PrintTest.csproj.user
     文件         521  2017-09-20 15:52  PrintTest\PrintTest\Program.cs
     目录           0  2017-09-20 15:52  PrintTest\PrintTest\Properties\
     文件        1326  2017-09-20 15:52  PrintTest\PrintTest\Properties\AssemblyInfo.cs
     文件        2831  2017-09-20 15:52  PrintTest\PrintTest\Properties\Resources.Designer.cs
     文件        5612  2017-09-20 15:52  PrintTest\PrintTest\Properties\Resources.resx
     文件        1096  2017-09-20 15:52  PrintTest\PrintTest\Properties\Settings.Designer.cs
     文件         249  2017-09-20 15:52  PrintTest\PrintTest\Properties\Settings.settings
     目录           0  2017-09-26 14:19  PrintTest\PrintTest\Service References\
     文件     8388608  2017-09-26 14:18  PrintTest\PrintTest\Test.mdf
     文件     8388608  2017-09-26 14:18  PrintTest\PrintTest\Test_log.ldf
     目录           0  2017-09-20 15:52  PrintTest\PrintTest\bin\
     目录           0  2017-09-25 17:36  PrintTest\PrintTest\bin\Debug\
     文件       23552  2017-09-26 14:18  PrintTest\PrintTest\bin\Debug\PrintTest.exe
     文件         189  2017-09-20 15:52  PrintTest\PrintTest\bin\Debug\PrintTest.exe.config
     文件       22016  2017-09-26 14:18  PrintTest\PrintTest\bin\Debug\PrintTest.pdb
     文件       22696  2017-09-26 14:19  PrintTest\PrintTest\bin\Debug\PrintTest.vshost.exe
     文件         189  2017-09-20 15:52  PrintTest\PrintTest\bin\Debug\PrintTest.vshost.exe.config
     文件         490  2015-10-30 15:19  PrintTest\PrintTest\bin\Debug\PrintTest.vshost.exe.manifest
     文件     8388608  2017-09-26 14:18  PrintTest\PrintTest\bin\Debug\Test.mdf
............此处省略17个文件信息

评论

共有 条评论