C#编程-137:PrintPreviewControl打印预览控件
标签:
csharp |
分类: 科技 |
http://s16/mw690/002NehRPzy7dAYs97UX5f&690
-
using
System; -
using
System.Collections.Generic; -
using
System.ComponentModel; -
using
System.Data; -
using
System.Drawing; -
using
System.Linq; -
using
System.Text; -
using
System.Windows.Forms; -
-
namespace
PrintPreviewTest - {
-
publicpartial class Form1 : Form -
{ -
publicForm1() -
{ -
InitializeComponent(); -
} -
-
privatevoid Form1_Load(object sender, EventArgs e) -
{ -
printPreviewControl1.Visible= false; -
btnCancel.Enabled= false; -
} -
-
privatevoid btnPreview_Click(object sender, EventArgs e) -
{ -
try -
{ -
printPreviewControl1.Document= printDocument1; -
printPreviewControl1.Visible= true; -
btnCancel.Enabled= true; -
btnPreview.Enabled= false; -
} -
catch(Exception ex) -
{ -
-
MessageBox.Show(ex.Message,"预览出错",MessageBoxButtons.OK,MessageBoxIcon.Error); -
} -
} -
-
privatevoid btnCancel_Click(object sender, EventArgs e) -
{ -
printPreviewControl1.Visible= false; -
btnCancel.Enabled= false; -
btnPreview.Enabled= true; -
} -
-
privatevoid printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) -
{ -
intx = e.PageBounds.Left+10; -
inty = e.PageBounds.Top+50; -
Graphicsg = e.Graphics; -
Fontfont new= Font("黑体",100); -
SolidBrushbrush new= SolidBrush(Color.Green); -
stringtext="此处输入需要打印的内容"; -
g.DrawString(text,font,brush,x,y); -
} -
} - }
后一篇:C#编程-138:网络编程基础

加载中…