在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例常用C#方法 → c#中winform窗体进行打印

c#中winform窗体进行打印

常用C#方法

下载此实例
  • 开发语言:C#
  • 实例大小:0.19M
  • 下载次数:188
  • 浏览次数:1468
  • 发布时间:2018-01-23
  • 实例类别:常用C#方法
  • 发 布 人:心辰
  • 文件格式:.rar
  • 所需积分:3
 相关标签: winform C# c 打印 ORM

实例介绍

【实例简介】
【实例截图】

from clipboard

from clipboard

from clipboard

【核心代码】

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 Print
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.printDocument1.OriginAtMargins = true;//启用页边距
            this.pageSetupDialog1.EnableMetric = true;//以毫米为单位
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.pageSetupDialog1.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.printPreviewDialog1.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
            {

                this.printDocument1.Print();
            }
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            ////打印内容 为 局部的 this.groupBox1
            //Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height);
            //groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
            //e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height); 

            ////打印内容 为 整个Form
            //Image myFormImage;
            //myFormImage = new Bitmap(this.Width, this.Height);
            //Graphics g = Graphics.FromImage(myFormImage);
            //g.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
            //e.Graphics.DrawImage(myFormImage, 0, 0);

            //打印内容 为 自定义文本内容 
            //Font font = new Font("宋体", 12);
            //Brush bru = Brushes.Blue;
            //for (int i = 1; i <= 5; i  )
            //{
            //    e.Graphics.DrawString("Hello world ", font, bru, i * 20, i * 20);
            //}

            Graphics MyGraphics = e.Graphics;//获得绘图对象
            SolidBrush drawBrush = new SolidBrush(Color.Black);
            Font drawFont = new Font("方正魏碑简体", 15, FontStyle.Bold);
            Font drawFont1 = new Font("华文细黑", 9);
            Color color = Color.Black;
            Pen myPen = new Pen(color, 1);

            MyGraphics.DrawString("会 客 单", drawFont, drawBrush, 100, 0);
           

            MyGraphics.DrawString("登记时间:"   DateTime.Now.ToString(), drawFont1, drawBrush, 10, 45);

            MyGraphics.DrawRectangle(myPen, 0, 62, 68, 30);
            MyGraphics.DrawString("访客姓名", drawFont1, drawBrush, 8, 70);

            MyGraphics.DrawRectangle(myPen, 68, 62, 110, 30);
            string name = username.Text;
            if (name.Length > 7)
            {
                MyGraphics.DrawString(name.Substring(0, 7), drawFont1, drawBrush, 68, 64);
                MyGraphics.DrawString(name.Substring(7, name.Length - 7), drawFont1, drawBrush, 68, 77);
            }
            else
            {
                MyGraphics.DrawString(name, drawFont1, drawBrush, 68, 70);
            }

            MyGraphics.DrawRectangle(myPen, 0, 92, 68, 24);
            MyGraphics.DrawString("访客性别", drawFont1, drawBrush, 8, 97);
            MyGraphics.DrawRectangle(myPen, 68, 92, 110, 24);
            MyGraphics.DrawString(sex.Text, drawFont1, drawBrush, 68, 97);

            MyGraphics.DrawRectangle(myPen, 0, 116, 68, 24);
            MyGraphics.DrawString("访客电话", drawFont1, drawBrush, 8, 121);
            MyGraphics.DrawRectangle(myPen, 68, 116, 110, 24);
            MyGraphics.DrawString(phone.Text, drawFont1, drawBrush, 68, 121);

            MyGraphics.DrawRectangle(myPen, 0, 140, 68, 24);
            MyGraphics.DrawString("车牌号码", drawFont1, drawBrush, 8, 145);
            MyGraphics.DrawRectangle(myPen, 68, 140, 110, 24);
            MyGraphics.DrawString(carnum.Text, drawFont1, drawBrush, 68, 145);

            MyGraphics.DrawRectangle(myPen, 0, 164, 68, 24);
            MyGraphics.DrawString("来访人数", drawFont1, drawBrush, 8, 169);
            MyGraphics.DrawRectangle(myPen, 68, 164, 110, 24);
            MyGraphics.DrawString(renshu.Text, drawFont1, drawBrush, 68, 169);

            MyGraphics.DrawRectangle(myPen, 178, 62, 105, 126);
            if (pictureBox1.Image != null)
            {
                MyGraphics.DrawImage(pictureBox1.Image, 178, 62, 103, 124);
            }

            MyGraphics.DrawRectangle(myPen, 0, 188, 68, 24);
            MyGraphics.DrawString("来访事由", drawFont1, drawBrush, 8, 193);
            MyGraphics.DrawRectangle(myPen, 68, 188, 215, 24);
            MyGraphics.DrawString(matter.Text, drawFont1, drawBrush, 68, 193);

            MyGraphics.DrawRectangle(myPen, 0, 212, 68, 24);
            MyGraphics.DrawString("证件号码", drawFont1, drawBrush, 8, 217);
            MyGraphics.DrawRectangle(myPen, 68, 212, 215, 24);
            MyGraphics.DrawString(card.Text, drawFont1, drawBrush, 68, 217);

            MyGraphics.DrawRectangle(myPen, 0, 236, 68, 30);
            MyGraphics.DrawString("证件地址", drawFont1, drawBrush, 8, 244);
            MyGraphics.DrawRectangle(myPen, 68, 236, 215, 30);
            string addressstr = address.Text;
            if (addressstr.Length > 16)
            {
                MyGraphics.DrawString(addressstr.Substring(0, 16), drawFont1, drawBrush, 68, 238);
                MyGraphics.DrawString(addressstr.Substring(16, addressstr.Length - 16), drawFont1, drawBrush, 68, 251);
            }
            else
            {
                MyGraphics.DrawString(addressstr, drawFont1, drawBrush, 68, 238);
            }

            MyGraphics.DrawRectangle(myPen, 0, 266, 68, 24);
            MyGraphics.DrawString("携带物品", drawFont1, drawBrush, 8, 271);
            MyGraphics.DrawRectangle(myPen, 68, 266, 215, 24);
            MyGraphics.DrawString(wupin.Text, drawFont1, drawBrush, 68, 271);

            MyGraphics.DrawRectangle(myPen, 0, 290, 68, 24);
            MyGraphics.DrawString("被访人部门", drawFont1, drawBrush, 2, 295);
            MyGraphics.DrawRectangle(myPen, 68, 290, 215, 24);
            MyGraphics.DrawString(bfbm.Text, drawFont1, drawBrush, 68, 295);

            MyGraphics.DrawRectangle(myPen, 0, 314, 68, 24);
            MyGraphics.DrawString("被访人姓名", drawFont1, drawBrush, 2, 319);
            MyGraphics.DrawRectangle(myPen, 68, 314, 215, 24);
            MyGraphics.DrawString(bfxm.Text, drawFont1, drawBrush, 68, 319);

            MyGraphics.DrawRectangle(myPen, 0, 338, 68, 24);
            MyGraphics.DrawString("被访人签名", drawFont1, drawBrush, 2, 343);
            MyGraphics.DrawRectangle(myPen, 68, 338, 143, 24);

            MyGraphics.DrawRectangle(myPen, 0, 362, 68, 24);
            MyGraphics.DrawString("登记单号", drawFont1, drawBrush, 8, 367);
            MyGraphics.DrawRectangle(myPen, 68, 362, 143, 24);
            MyGraphics.DrawString(djnum.Text, drawFont1, drawBrush, 68, 367);

            MyGraphics.DrawRectangle(myPen, 0, 386, 211, 24);
            MyGraphics.DrawString("请妥善保留,离开时交换门卫", drawFont1, drawBrush, 25, 391);

            MyGraphics.DrawRectangle(myPen, 211, 338, 72, 72);
            if (pictureBox2.Image != null)
            {
                MyGraphics.DrawImage(pictureBox2.Image, 211, 338, 72, 72);
            }



        }

       

        
    }
}

标签: winform C# c 打印 ORM

实例下载地址

c#中winform窗体进行打印

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警