WindowsForm 打印

摘要:
打印:打印对话框:打印对话框页面设置:页面设置对话框两个对话框都需要通过设置打印文档来指定打印对象打印文档:打印对象必须具有绘图板,以便在打印机和打印内容之间进行传输。打印机打印printdomentprintDocument1_PrintPage:事件,在打印每页之前触发,用于指定打印文档的打印内容

打印:


打印对话框:printdialog
页面设置:pagesetupdialog
这两个对话框都需要通过设置printdocument来指定打印对象
printdocument:打印对象,必须要有,一块画板,用于打印机与打印内容之间中转,打印机打印的是printdoment
printDocument1_PrintPage:事件,每打印一页之前触发,用于给printdocument指定打印内容
通过画板把内容画到打印对象的页上:
System.Drawing.Font f = new System.Drawing.Font("宋体",12);
e.Graphics.DrawString(textBox1.Text,f,System.Drawing.Brushes.Aqua,5,5);
最后打印: 打印对话框那,如果打印对话框返回确定打印,就执行printdocument.print();

看一下打印界面

WindowsForm 打印第1张

下面是打印界面的代码 (点击小加号打开)

WindowsForm 打印第2张WindowsForm 打印第3张
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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


        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            string upass = textBox2.Text;
            //连接数据库
            SqlConnection conn = new SqlConnection("server=.;database=data1220;user=sa;pwd=123");
            conn.Open();
            //执行语句
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from users where uname='" + username + "'and upass='" + upass + "'";
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                //MessageBox.Show(dr["uname"].ToString());
                MessageBox.Show("登陆成功");

            }
            else
            {
                MessageBox.Show("登录失败");
            }
            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //添加数据到数据库

            string username = textBox1.Text;
            string upass = textBox2.Text;

            //连接数据库
            SqlConnection conn = new SqlConnection("server=.;database=data1220;user=sa;pwd=123");
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "insert into users values ('" + username + "'," + upass + ") ";
            int count = cmd.ExecuteNonQuery();//增删改
            if (count > 0)
            {
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
            conn.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string code = textBox3.Text;
            string uname = textBox1.Text;
            string upass = textBox2.Text;
            //连接数据库
            SqlConnection conn = new SqlConnection("server=.;database=data1220;user=sa;pwd=123");
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "update users set uname='" + uname + "',upass='" + upass + "'where code=" + code;
            int count = cmd.ExecuteNonQuery();

            if (count > 0)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
            conn.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string code = textBox3.Text;
            //连接数据库
            SqlConnection conn = new SqlConnection("server=.;database=data1220;user=sa;pwd=123");
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "delete from user where code=" + code;
            cmd.ExecuteNonQuery();
            conn.Close();
        }

    }
}
打印的 代码

免责声明:文章转载自《WindowsForm 打印》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇CI框架入门笔记selenium定位多个嵌套iframe下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

UOS上如何安装rpm包

UOS的软件包格式是deb,如果要安装rpm的包则要先把rpm转换成deb才可以安装。步骤如下:1、UOS下安装aliensudoapt-getinstallalien2、将rpm包转为deb包sudoalien-dxxxx.rpm#将rpm转换位deb成功后会生成一个同名的xxxx.deb3、安装deb包sudodpkg-ixxxx.deb注意,用alie...

[npm CLI文档]配置NPM:package-lock.json

包装锁。json和npm shrink-wrap json将两个文件以相同的格式进行比较,并在项目的根目录中执行类似的功能。不同之处在于包锁Json无法发布,如果在根目录之外的任何位置找到它,就会被忽略。隐藏的锁定文件避免重复处理nodes_Modules文件夹。从v7开始,npm使用node_modules/.package锁。json中的“隐藏”锁文件。...

【转】QImage 图像格式小结

构造图像:,QImagemyImage1=QImage;根据文件名打开图像。如果图像本身是32位或24位,则程序中的图像是32位。如果图像本身是8位或1位,则程序中的对应图像是8位或者1位。宽度表示图像宽度,高度表示图像高度。...

前端chrome浏览器调试总结

以下选项允许您选择要捕获的项目。...

iTerm2 配色方案(转)

ITerm2配色方案(噢,我的zsh&Powerline)item2.png转到官方网站下载ITerm2,并以全黑色背景打开它。屏幕截图2017-08-01下午5.45.28点。Pngsolarized可以说是目前网络上最流行的配色方案,我个人认为比较这种配色更好。第一种方法:打开iTerm2首选项、配置文件/颜色,然后直接选择Solariz...

关于WINFORM中输入法的设置

关于WINFORM(转移到)John Suna的专栏开发中输入方法的设置,它碰巧遇到了这种问题。网络真的很好:)这是文本集。感谢作者的辛勤工作给您带来的便利。在WINFORM中,我们经常遇到这样的问题:文本输入框中的输入法被禁用或总是更改为全宽输入法。查阅相关数据后,总结如下:(1)Control.ImeMode属性:获取或设置控件的输入方法编辑器模式。此模...