首页 > 编程语言 >WINFORM简单套打程序示例

WINFORM简单套打程序示例

时间:2024-11-08 11:10:25浏览次数:1  
标签:示例 Text void 程序 System y1 using font WINFORM

1、软件界面(printDialog和printdocument两个控件显示 在下方)

 

 

2、主要代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string symblString1, symblString2;
                symblString1 = "";
                symblString2 = "";
                if (txtDate.Text == "" || txtBatchNo.Text == "")
                {
                    MessageBox.Show("批次和日期必须填写!");
                    return;
                }
                if (printDialog1.ShowDialog() == DialogResult.OK)
                {
                    printDocument1.Print();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("程序出错,错误信息为:" + ex.Message);
            }
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            try
            {

               
                int num1 = 200;
                //标签文字开始X点
                //文字从第几列开始打,横坐标
                int x1 = 280;
                //文字开始打印的高度
                int y1 = 111;
                int yStep = 50;  //行间距
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;
                Pen pen = new Pen(Color.Black, 1f);
                Font font = new Font("宋体", 17f, FontStyle.Bold);
               //黑色笔
                 Brush fontColor = Brushes.Black;
                // 绘制到屏幕上。
                //批号
                e.Graphics.DrawString(txtBatchNo.Text, font, fontColor, x1, y1);
                y1 = y1 + yStep+70;
                //装箱员
                e.Graphics.DrawString(txtOperator.Text, font, fontColor, x1 + 215, y1);
                y1 = y1 + yStep;
                //装箱日期
                e.Graphics.DrawString(txtDate.Text, font, fontColor, x1 + 215, y1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txtDate.Text = DateTime.Now.ToString("yyyy.MM.dd");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

 

标签:示例,Text,void,程序,System,y1,using,font,WINFORM
From: https://www.cnblogs.com/lrzy/p/18534711

相关文章