当前位置: 首页>>代码示例>>C#>>正文


C# PrintPreviewDialog.Document属性代码示例

本文整理汇总了C#中System.Windows.Forms.PrintPreviewDialog.Document属性的典型用法代码示例。如果您正苦于以下问题:C# PrintPreviewDialog.Document属性的具体用法?C# PrintPreviewDialog.Document怎么用?C# PrintPreviewDialog.Document使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.PrintPreviewDialog的用法示例。


在下文中一共展示了PrintPreviewDialog.Document属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Form1

//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    
    private System.ComponentModel.Container components = null;
    private System.Drawing.Printing.PrintDocument ThePrintDocument = null;
    private System.IO.StringReader myStringReader = null;

    public Form1() {
        ThePrintDocument = new System.Drawing.Printing.PrintDocument();
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        this.button1.Location = new System.Drawing.Point(112, 352);
        this.button1.Text = "&Preview";
        this.button1.Click += new System.EventHandler(this.button1_Click);
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(512, 397);
        this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1 });
        this.ResumeLayout(false);
    }

    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected void PrintPage(object sender,
        System.Drawing.Printing.PrintPageEventArgs ev) {
        float linesPerPage = 0;
        float yPosition = 0;
        int count = 0;
        float leftMargin = ev.MarginBounds.Left;
        float topMargin = ev.MarginBounds.Top;
        string line = null;
        Font printFont = this.Font;
        SolidBrush myBrush = new SolidBrush(Color.Black);

        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
        while (count < linesPerPage && ((line = myStringReader.ReadLine()) != null)) {
            yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics));
            ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
            count++;
        }
        if (line != null)
            ev.HasMorePages = true;
        else
            ev.HasMorePages = false;

        myBrush.Dispose();
    }

    private void button1_Click(object sender, System.EventArgs e) {
        ThePrintDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintPage);
        string strText = "STRING";
        myStringReader = new System.IO.StringReader(strText);
        PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
        printPreviewDialog1.Document = this.ThePrintDocument;
        printPreviewDialog1.ShowDialog();
    }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:69,代码来源:PrintPreviewDialog.Document


注:本文中的System.Windows.Forms.PrintPreviewDialog.Document属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。