zoukankan      html  css  js  c++  java
  • WindowsForm 打印

    打印:


    打印对话框: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();

    看一下打印界面

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

    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();
            }
    
        }
    }
    打印的 代码
  • 相关阅读:
    阅读笔记:管理学
    Vs2010中文版MSDN 安装方法
    .NET 产品版权保护方案 (.NET源码加密保护)
    WPF 判断是否为设计(Design)状态
    重写成员时违反了继承安全性规则。重写方法的安全可访问性必须与所重写方法的安全可访问性匹配。
    没有为此解决方案配置选中要生成的项目 .
    何崚谈阿里巴巴前端性能优化最佳实践
    Oracle10GODP连接11G数据库,出现ORA 1017用户名/口令无效; 登录被拒绝 的问题
    HTTP、TCP、UDP、Socket (转)
    编译的时候生成.g.cs还有.g.i.cs,有什么区别?
  • 原文地址:https://www.cnblogs.com/981971554nb/p/4324598.html
Copyright © 2011-2022 走看看