frmEasyPrint.cs
资源名称:GOLDPRINT.rar [点击查看]
上传用户:jx_fiona
上传日期:2014-03-08
资源大小:1387k
文件大小:11k
源码类别:
打印编程
开发平台:
Others
- using System;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using GoldPrinter;
- namespace MisGoldPrinterTest
- {
- /// <summary>
- /// 打印示例--简单快捷、易用实用
- /// </summary>
- public class frmEasyPrint : System.Windows.Forms.Form
- {
- //*****第一步*****:申明并实例化,可用带参构造函数指明默认横向显示/打印。
- //如果你不写完整的名字空间,请使用using GoldPrinter;
- private GoldPrinter.MisGoldPrinter misGoldPrinter = new GoldPrinter.MisGoldPrinter(true);
- //简单打印示例
- private void Print(bool p_PrintOrPreview)
- {
- //*****第二步*****:直接赋值给打印对象(可选)
- //更精彩应用,请单击菜单 “更多激动人心示例对象定制变换无穷”
- misGoldPrinter.Title = "金质打印通 通打天下报表nWWW.WebMIS.COM.CN"; //主标题(C#用n表示换行)
- misGoldPrinter.Caption = " ——GoldPrinter,欢迎下载"; //副标题
- misGoldPrinter.Top = "作者:周方勇|2004-08-19|版本:V2.5"; //抬头,一行三列的文字说明,用|分隔
- misGoldPrinter.Bottom = "打印程序开源版||打印日期:" + System.DateTime.Now.ToLongDateString(); //结尾,说明同抬头
- //*****第三步*****:打印重点,设置数据源
- //可以是一维数组、二维数组、DataGrid、DataTable、ListView、MshFlexGrid、HtmlTable...,
- //总之,不支持的你自己写一个函数转换成二维数组赋给DataSource一切搞定
- misGoldPrinter.DataSource = this.dataGrid1; //DataGrid作为数据源
- //打印的核心是Body,可以对它设置字体、列宽等等
- ((GoldPrinter.Body)(misGoldPrinter.Body)).IsAverageColsWidth = true;//指明平均列宽
- //*****第四步*****:打印或预览
- if (p_PrintOrPreview)
- {
- misGoldPrinter.Print(); //打印
- }
- else
- {
- misGoldPrinter.Preview(); //预览
- }
- }
- private void frmPrint_Closed(object sender, System.EventArgs e)
- {
- //*****第五步*****:用完释放
- misGoldPrinter.Dispose();
- misGoldPrinter = null;
- }
- //打印或预览 菜单:页面设置、打印机设置、打印预览
- private void menuFilePageSetup_Click(object sender, System.EventArgs e)
- {
- misGoldPrinter.PageSetup();
- }
- private void menuFilePrintPreview_Click(object sender, System.EventArgs e)
- {
- Print(false);
- }
- private void menuFilePrint_Click(object sender, System.EventArgs e)
- {
- Print(true);
- }
- private void menuFileExit_Click(object sender, System.EventArgs e)
- {
- Application.Exit();
- }
- //加载打印示例数据
- private void frmPrint_Load(object sender, System.EventArgs e)
- {
- this.dataGrid1.DataSource = PrintDataSource.GetDataSource(500);
- }
- private void menuHelpAbout_Click(object sender, System.EventArgs e)
- {
- frmAbout frmInstance = new frmAbout();
- frmInstance.ShowDialog();
- frmInstance.Dispose();
- }
- private void menuEgCompletePrint_Click(object sender, System.EventArgs e)
- {
- frmCompletePrint frmInstance = new frmCompletePrint();
- frmInstance.ShowDialog();
- frmInstance.Dispose();
- }
- private void menuEgExcel_Click(object sender, System.EventArgs e)
- {
- frmExcelPrint frmInstance = new frmExcelPrint();
- frmInstance.ShowDialog();
- frmInstance.Dispose();
- }
- private void menuEgCasePrint_Click(object sender, System.EventArgs e)
- {
- frmInvoice frmInstance = new frmInvoice();
- frmInstance.ShowDialog();
- frmInstance.Dispose();
- }
- #region Windows 窗体设计器生成的代码
- private System.Windows.Forms.MainMenu mainMenu1;
- private System.Windows.Forms.MenuItem menuFile;
- private System.Windows.Forms.MenuItem menuFilePageSetup;
- private System.Windows.Forms.MenuItem menuFilePrintPreview;
- private System.Windows.Forms.MenuItem menuFilePrint;
- private System.Windows.Forms.DataGrid dataGrid1;
- private System.Windows.Forms.MenuItem menuFileExit;
- private System.Windows.Forms.MenuItem menuHelp;
- private System.Windows.Forms.MenuItem menuHelpAbout;
- private System.Windows.Forms.MenuItem menuOtherExamples;
- private System.Windows.Forms.MenuItem menuEgExcel;
- private System.Windows.Forms.MenuItem menuEgCompletePrint;
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MenuItem menuEgCasePrint;
- private System.Windows.Forms.MenuItem menuVs2005DataGridViewPt;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public frmEasyPrint()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.mainMenu1 = new System.Windows.Forms.MainMenu();
- this.menuFile = new System.Windows.Forms.MenuItem();
- this.menuFilePageSetup = new System.Windows.Forms.MenuItem();
- this.menuFilePrintPreview = new System.Windows.Forms.MenuItem();
- this.menuFilePrint = new System.Windows.Forms.MenuItem();
- this.menuFileExit = new System.Windows.Forms.MenuItem();
- this.menuOtherExamples = new System.Windows.Forms.MenuItem();
- this.menuEgCompletePrint = new System.Windows.Forms.MenuItem();
- this.menuEgExcel = new System.Windows.Forms.MenuItem();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.menuEgCasePrint = new System.Windows.Forms.MenuItem();
- this.menuVs2005DataGridViewPt = new System.Windows.Forms.MenuItem();
- this.menuHelp = new System.Windows.Forms.MenuItem();
- this.menuHelpAbout = new System.Windows.Forms.MenuItem();
- this.dataGrid1 = new System.Windows.Forms.DataGrid();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
- this.SuspendLayout();
- //
- // mainMenu1
- //
- this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuFile,
- this.menuOtherExamples,
- this.menuVs2005DataGridViewPt,
- this.menuHelp});
- //
- // menuFile
- //
- this.menuFile.Index = 0;
- this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuFilePageSetup,
- this.menuFilePrintPreview,
- this.menuFilePrint,
- this.menuFileExit});
- this.menuFile.Text = "文件(&F)";
- //
- // menuFilePageSetup
- //
- this.menuFilePageSetup.Index = 0;
- this.menuFilePageSetup.Text = "页面设置(&U)...";
- this.menuFilePageSetup.Click += new System.EventHandler(this.menuFilePageSetup_Click);
- //
- // menuFilePrintPreview
- //
- this.menuFilePrintPreview.Index = 1;
- this.menuFilePrintPreview.Text = "打印预览(&V)";
- this.menuFilePrintPreview.Click += new System.EventHandler(this.menuFilePrintPreview_Click);
- //
- // menuFilePrint
- //
- this.menuFilePrint.Index = 2;
- this.menuFilePrint.Text = "打印(&P)...";
- this.menuFilePrint.Click += new System.EventHandler(this.menuFilePrint_Click);
- //
- // menuFileExit
- //
- this.menuFileExit.Index = 3;
- this.menuFileExit.Text = "退出(&X)";
- this.menuFileExit.Click += new System.EventHandler(this.menuFileExit_Click);
- //
- // menuOtherExamples
- //
- this.menuOtherExamples.Index = 1;
- this.menuOtherExamples.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuEgCompletePrint,
- this.menuEgExcel,
- this.menuItem1,
- this.menuEgCasePrint});
- this.menuOtherExamples.Text = "更多激动人心示例(完全示例、Excel、套打)(&E)";
- //
- // menuEgCompletePrint
- //
- this.menuEgCompletePrint.Index = 0;
- this.menuEgCompletePrint.Text = "对象定制变换无穷";
- this.menuEgCompletePrint.Click += new System.EventHandler(this.menuEgCompletePrint_Click);
- //
- // menuEgExcel
- //
- this.menuEgExcel.Index = 1;
- this.menuEgExcel.Text = "Excel通打天下报表";
- this.menuEgExcel.Click += new System.EventHandler(this.menuEgExcel_Click);
- //
- // menuItem1
- //
- this.menuItem1.Index = 2;
- this.menuItem1.Text = "-";
- //
- // menuEgCasePrint
- //
- this.menuEgCasePrint.Index = 3;
- this.menuEgCasePrint.Text = "套打经典,国税发票";
- this.menuEgCasePrint.Click += new System.EventHandler(this.menuEgCasePrint_Click);
- //
- // menuVs2005DataGridViewPt
- //
- this.menuVs2005DataGridViewPt.Index = 2;
- this.menuVs2005DataGridViewPt.Text = "Vs2005DataGridView、ListView打印";
- this.menuVs2005DataGridViewPt.Click += new System.EventHandler(this.menuVs2005DataGridViewPt_Click);
- //
- // menuHelp
- //
- this.menuHelp.Index = 3;
- this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuHelpAbout});
- this.menuHelp.Text = "帮助(&H)";
- //
- // menuHelpAbout
- //
- this.menuHelpAbout.Index = 0;
- this.menuHelpAbout.Text = "关于 MIS金质打印通(&A)...";
- this.menuHelpAbout.Click += new System.EventHandler(this.menuHelpAbout_Click);
- //
- // dataGrid1
- //
- this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.dataGrid1.ColumnHeadersVisible = false;
- this.dataGrid1.DataMember = "";
- this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid1.Location = new System.Drawing.Point(0, 0);
- this.dataGrid1.Name = "dataGrid1";
- this.dataGrid1.Size = new System.Drawing.Size(720, 400);
- this.dataGrid1.TabIndex = 0;
- //
- // frmEasyPrint
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.BackColor = System.Drawing.SystemColors.Control;
- this.ClientSize = new System.Drawing.Size(720, 401);
- this.Controls.Add(this.dataGrid1);
- this.Menu = this.mainMenu1;
- this.Name = "frmEasyPrint";
- this.Text = "简单快捷、易用实用 -- MIS金质打印通 打印示例";
- this.Load += new System.EventHandler(this.frmPrint_Load);
- this.Closed += new System.EventHandler(this.frmPrint_Closed);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new frmEasyPrint());
- }
- #endregion
- private void menuVs2005DataGridViewPt_Click(object sender, System.EventArgs e)
- {
- string strMsg = @"请见金质打印通工程 GoldPrintDataGridViewListViewHelper.cs说明。" + "n另参见 VS.NET打印思想与2003/5DataGrid、DataGridView及二维数据如ListView等终极打印实现。";
- MessageBox.Show(strMsg,"金质打印通 www.webmis.com.cn免费源码!");
- }
- }//End Class
- }//End Namespace