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 > )
{
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 > )
{
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 打印的更多相关文章
- c# windowsForm打印
在windows应用程序中文档的打印是一项非常重要的功能,在以前一直是一个非常复杂的工作,Microsoft .net Framework的打 印功能都以组件的方式提供,为程序员提供了很大的方便,但是 ...
- WindowsForm如何实现类似微软project软件的甘特图?
在管理软件研发过程中,特别是涉及项目管理或者生产计划方面,都需要一款类似微软project的控件对项目下的分解任务进行图形展示(甘特图).下面介绍一下在WindowsForm下如何实现类似微软proj ...
- PrintDocument打印、预览、打印机设置和打印属性的方法
WindowsForm 使用 PrintDocument打印.预览.打印机设置和打印属性的方法. private void Form1_Load(object sender, System.Event ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(55)-Web打印
系列目录 前言 1.本次主要弥补工作流,用户表单数据的打印 2.使用JQprint做为web打印插件 3.兼容:FireFox,Chrome,IE. 4.没有依赖也没有配置,使用简单 代码下载:htt ...
- C#中5步完成word文档打印的方法
在日常工作中,我们可能常常需要打印各种文件资料,比如word文档.对于编程员,应用程序中文档的打印是一项非常重要的功能,也一直是一个非常复杂的工作.特别是提到Web打印,这的确会很棘手.一般如果要想选 ...
- 开源免费且稳定实用的.NET PDF打印组件itextSharp(.NET组件介绍之八)
在这个.NET组件的介绍系列中,受到了很多园友的支持,一些园友(如:数据之巅. [秦时明月]等等这些大神 )也给我提出了对应的建议,我正在努力去改正,有不足之处还望大家多多包涵.在传播一些简单的知识的 ...
- Ajax使用WCF实现小票pos机打印源码
通过ajax跨域方式调用WCF服务,实现小票pos机的打印,源码提供web方式,客户端方式测试,服务驻留右侧底部任务栏,可控制服务开启暂停,用户可自定义小票打印模板,配合零售录入. qq 22945 ...
- Jqprint实现页面打印
好些项目需要实现页面打印,特别是一些后台管理类系统,下面介绍一款轻量级的打印插件: 1.实现页面打印要引入jQuery和Jqprint.点击下载Jqprint插件 <script languag ...
- Android连接网络打印机进行打印
首先这是网络打印工具类,通过Socket实现,多说一句,网络打印机端口号一般默认的是9100 package com.Ieasy.Tool; import android.annotation.Sup ...
随机推荐
- android 注释常用标签
javadoc: {@link ActivityGroup} 链接到包.类: {@link #setContentView} 用#链接到类成员: @return View The current ...
- Biztalk2010安装及配置问题集
在安装Biztalk2010时,碰到很多问题,有的是粗心有的也是比较bt的,如: 1)在win7 64下引入x86 的cab,有点粗心,幸亏给我报错版本不兼容(呵呵): 2)安装的时候 不知道为什么计 ...
- javascript事件捕获与冒泡
对“捕获”和“冒泡”这两个概念,我想我们对冒泡更熟悉一些,因为在我们使用的所有浏览器中,都支持事件冒泡,即事件由子元素向祖先元素传播的,就 像气泡从水底向水面上浮一样.而在像firefox,chrom ...
- ssh整合web.xml过滤器和监听器的配置 .
延迟加载过滤器 Hibernate 允许对关联对象.属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行.如果 Service 层返回一个启用了延迟 ...
- Python中for\while的用法
代码示例 board = [] for i in range(5): board.append(i) print board board = [] i = 0 while i < 5: boar ...
- Reactor模型
Reactor模型 原文地址:http://www.ivaneye.com/2016/07/23/iomodel.html 无处不在的C/S架构 在这个充斥着云的时代,我们使用的软件可以说99%都是C ...
- 使用ARM模板部署自动扩展的Linux VMSS(1)
在Azure之前的ASM版本或者经典模式中,用户使用Azure Website,Azure Cloud Service等PAAS服务,可以实现一定程度上的自动扩展(auto scaling),但有着诸 ...
- Java 之String.valueOf(obj)
实例代码如下: String str = null; String uSelectDate = String.valueOf(str); System.out.println("====== ...
- 解决 setOnItemClickListener,setOnScrollListener与setOnTouchListener事件冲突问题
代码案例如下: lvXxsdMore.setOnItemClickListener(xxsdMoreListener); //对listView 注册onclick事件 lvXxsdMore.setO ...
- 开源欣赏wordpress之用户新增user-new.php
require_once( dirname( __FILE__ ) . '/admin.php' ); 引入根文件. if ( is_multisite() ) { if ( ! current_us ...