C#中的PageSetupDialog组件的应用实例_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2769 | 回复: 0   主题: C#中的PageSetupDialog组件的应用实例        下一篇 
    本主题由 koei123 于 2015-2-6 5:07:10 移动
likeavirgin
注册用户
等级:新兵
经验:66
发帖:3
精华:0
注册:1970-1-1
状态:离线
发送短消息息给likeavirgin 加好友    发送短消息息给likeavirgin 发消息
发表于: IP:您无权察看 2015-1-9 16:48:51 | [全部帖] [楼主帖] 楼主

PageSetupDialog组件的应用

下面通过一个例子来说明PageSetupDialog组件的用法。

程序开发步骤如下所示。

(1)在VS 2005中新建一个项目,选择Windows窗体模板,并命名为PageSetupDialog。给窗体添加一个PageSetupDialog组件,然后再添加一个PrintDocument组件。

(2)在窗体中继续添加一个Button按钮,并将按钮的Text属性值设置为“打印”,然后在click事件中添加如下代码:

private void button1_Click(object sender, EventArgs e)
{
      pageSetupDialog1.Document = printDocument1;
      pageSetupDialog1.ShowDialog();
}


示例运行结果如图1所示。

完整程序代码如下:

★   ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PageSetupDialog
{
      public partial class Form1 : Form
      {
            public Form1()
            {
                  InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                  pageSetupDialog1.Document = printDocument1;
                  pageSetupDialog1.ShowDialog();
                  printDialog1.Document = printDocument1;
                  printDialog1.ShowDialog();
            }
      }
}


★   ★★★★Form1.designer.cs窗体设计文件完整程序代码★★★★★

namespace PageSetupDialog
{
      partial class Form1
      {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;
            /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                  if (disposing && (components != null))
                  {
                        components.Dispose();
                  }
                  base.Dispose(disposing);
            }
            #region Windows 窗体设计器生成的代码
            /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
            this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
            this.printDocument1 = new System.Drawing.Printing.PrintDocument();
            this.button1 = new System.Windows.Forms.Button();
            this.printDialog1 = new System.Windows.Forms.PrintDialog();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(185, 258);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;


this.button1.Text = "打印";

this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// printDialog1
//
this.printDialog1.UseEXDialog = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(463, 373);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
private System.Drawing.Printing.PrintDocument printDocument1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.PrintDialog printDialog1;
}
}


★   ★★★★Program.cs主程序文件完整程序代码★★★★★

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PageSetupDialog
{
      static class Program
      {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.EnableVisualStyles();
                  Application.SetCompatibleTextRenderingDefault(false);
                  Application.Run(new Form1());
            }
      }
}


--转自 北京联动北方科技有限公司



该贴由koei123转至本版2015-2-6 5:07:10



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论