<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FGUI_Windows_Forms%2FPrintDialog</id>
		<title>Csharp/CSharp Tutorial/GUI Windows Forms/PrintDialog - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FGUI_Windows_Forms%2FPrintDialog"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/GUI_Windows_Forms/PrintDialog&amp;action=history"/>
		<updated>2026-04-30T02:20:55Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/GUI_Windows_Forms/PrintDialog&amp;diff=5345&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/GUI_Windows_Forms/PrintDialog&amp;diff=5345&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/GUI_Windows_Forms/PrintDialog&amp;diff=5346&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/GUI_Windows_Forms/PrintDialog&amp;diff=5346&amp;oldid=prev"/>
				<updated>2010-05-26T12:15:04Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Display PrintDialog==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Drawing.Printing;&lt;br /&gt;
public class PrintDialogDemo : System.Windows.Forms.Form&lt;br /&gt;
{&lt;br /&gt;
  private System.Windows.Forms.TextBox txtFile;&lt;br /&gt;
  private System.Windows.Forms.Button btnOpenFile;&lt;br /&gt;
  private System.Windows.Forms.Button btnSaveFile;&lt;br /&gt;
  private System.ruponentModel.Container components = null;&lt;br /&gt;
  private System.Windows.Forms.Button btnPageSetup;&lt;br /&gt;
  private System.Windows.Forms.Button btnPrint;&lt;br /&gt;
  private System.Windows.Forms.Button btnPrintPreview;  &lt;br /&gt;
  &lt;br /&gt;
  private String strFileName;&lt;br /&gt;
  private Font currentFont = null;&lt;br /&gt;
  private PrintDocument printDocument = new PrintDocument();&lt;br /&gt;
  private StringReader stringReader;&lt;br /&gt;
  private OpenFileDialog openFileDialog = new OpenFileDialog();&lt;br /&gt;
  public PrintDialogDemo()&lt;br /&gt;
  {&lt;br /&gt;
    InitializeComponent();&lt;br /&gt;
    &lt;br /&gt;
    printDocument.PrintPage += new PrintPageEventHandler(pdPrintPage);&lt;br /&gt;
    printDocument.BeginPrint += new PrintEventHandler(pdBeginPrint);&lt;br /&gt;
    printDocument.EndPrint += new PrintEventHandler(pdEndPrint);&lt;br /&gt;
        currentFont= Font;&lt;br /&gt;
  }&lt;br /&gt;
  private void InitializeComponent()&lt;br /&gt;
  {&lt;br /&gt;
    this.txtFile = new System.Windows.Forms.TextBox();&lt;br /&gt;
    this.btnOpenFile = new System.Windows.Forms.Button();&lt;br /&gt;
    this.btnSaveFile = new System.Windows.Forms.Button();&lt;br /&gt;
    this.btnPageSetup = new System.Windows.Forms.Button();&lt;br /&gt;
    this.btnPrint = new System.Windows.Forms.Button();&lt;br /&gt;
    this.btnPrintPreview = new System.Windows.Forms.Button();&lt;br /&gt;
    this.SuspendLayout();&lt;br /&gt;
    // &lt;br /&gt;
    // txtFile&lt;br /&gt;
    // &lt;br /&gt;
    this.txtFile.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) &lt;br /&gt;
      | System.Windows.Forms.AnchorStyles.Left) &lt;br /&gt;
      | System.Windows.Forms.AnchorStyles.Right);&lt;br /&gt;
    this.txtFile.Location = new System.Drawing.Point(40, 24);&lt;br /&gt;
    this.txtFile.Multiline = true;&lt;br /&gt;
    this.txtFile.Name = &amp;quot;txtFile&amp;quot;;&lt;br /&gt;
    this.txtFile.Size = new System.Drawing.Size(500, 150);&lt;br /&gt;
    this.txtFile.TabIndex = 0;&lt;br /&gt;
    this.txtFile.Text = &amp;quot;&amp;quot;;&lt;br /&gt;
    // &lt;br /&gt;
    // btnOpenFile&lt;br /&gt;
    // &lt;br /&gt;
    this.btnOpenFile.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);&lt;br /&gt;
    this.btnOpenFile.Location = new System.Drawing.Point(48, 256);&lt;br /&gt;
    this.btnOpenFile.Name = &amp;quot;btnOpenFile&amp;quot;;&lt;br /&gt;
    this.btnOpenFile.TabIndex = 1;&lt;br /&gt;
    this.btnOpenFile.Text = &amp;quot;Open File&amp;quot;;&lt;br /&gt;
    this.btnOpenFile.Click += new System.EventHandler(this.btnOpenFile_Click);&lt;br /&gt;
    // &lt;br /&gt;
    // btnSaveFile&lt;br /&gt;
    // &lt;br /&gt;
    this.btnSaveFile.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);&lt;br /&gt;
    this.btnSaveFile.Location = new System.Drawing.Point(144, 256);&lt;br /&gt;
    this.btnSaveFile.Name = &amp;quot;btnSaveFile&amp;quot;;&lt;br /&gt;
    this.btnSaveFile.TabIndex = 2;&lt;br /&gt;
    this.btnSaveFile.Text = &amp;quot;Save File&amp;quot;;&lt;br /&gt;
    this.btnSaveFile.Click += new System.EventHandler(this.btnSaveFile_Click);&lt;br /&gt;
    // &lt;br /&gt;
    // btnPageSetup&lt;br /&gt;
    // &lt;br /&gt;
    this.btnPageSetup.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);&lt;br /&gt;
    this.btnPageSetup.Location = new System.Drawing.Point(240, 344);&lt;br /&gt;
    this.btnPageSetup.Name = &amp;quot;btnPageSetup&amp;quot;;&lt;br /&gt;
    this.btnPageSetup.TabIndex = 8;&lt;br /&gt;
    this.btnPageSetup.Text = &amp;quot;Page Setup&amp;quot;;&lt;br /&gt;
    this.btnPageSetup.Click += new System.EventHandler(this.btnPageSetup_Click);&lt;br /&gt;
    // &lt;br /&gt;
    // btnPrint&lt;br /&gt;
    // &lt;br /&gt;
    this.btnPrint.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);&lt;br /&gt;
    this.btnPrint.Location = new System.Drawing.Point(48, 344);&lt;br /&gt;
    this.btnPrint.Name = &amp;quot;btnPrint&amp;quot;;&lt;br /&gt;
    this.btnPrint.TabIndex = 6;&lt;br /&gt;
    this.btnPrint.Text = &amp;quot;Print&amp;quot;;&lt;br /&gt;
    this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);&lt;br /&gt;
    // &lt;br /&gt;
    // btnPrintPreview&lt;br /&gt;
    // &lt;br /&gt;
    this.btnPrintPreview.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);&lt;br /&gt;
    this.btnPrintPreview.Location = new System.Drawing.Point(144, 344);&lt;br /&gt;
    this.btnPrintPreview.Name = &amp;quot;btnPrintPreview&amp;quot;;&lt;br /&gt;
    this.btnPrintPreview.Size = new System.Drawing.Size(80, 23);&lt;br /&gt;
    this.btnPrintPreview.TabIndex = 7;&lt;br /&gt;
    this.btnPrintPreview.Text = &amp;quot;Print Preview&amp;quot;;&lt;br /&gt;
    this.btnPrintPreview.Click += new System.EventHandler(this.btnPrintPreview_Click);&lt;br /&gt;
    // &lt;br /&gt;
    // PrintDialogDemo&lt;br /&gt;
    // &lt;br /&gt;
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
    this.ClientSize = new System.Drawing.Size(592, 398);&lt;br /&gt;
    this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
                                             this.btnPrintPreview,&lt;br /&gt;
                                             this.btnPrint,&lt;br /&gt;
                                             this.btnPageSetup,&lt;br /&gt;
                                             this.btnSaveFile,&lt;br /&gt;
                                             this.btnOpenFile,&lt;br /&gt;
                                             this.txtFile});&lt;br /&gt;
    this.ResumeLayout(false);&lt;br /&gt;
  }&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Application.Run(new PrintDialogDemo());&lt;br /&gt;
  }&lt;br /&gt;
  private void btnOpenFile_Click(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    openFileDialog.InitialDirectory = @&amp;quot;c:\&amp;quot;;&lt;br /&gt;
    openFileDialog.Filter = &amp;quot;Text files (*.txt)|*.txt|&amp;quot; +&lt;br /&gt;
            &amp;quot;All files (*.*)|*.*&amp;quot;;&lt;br /&gt;
    openFileDialog.FilterIndex = 1;              //  1 based index&lt;br /&gt;
    &lt;br /&gt;
    if (openFileDialog.ShowDialog() == DialogResult.OK)&lt;br /&gt;
    {&lt;br /&gt;
      StreamReader reader = new StreamReader(openFileDialog.FileName);&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
        strFileName = openFileDialog.FileName;&lt;br /&gt;
        txtFile.Text = reader.ReadToEnd();&lt;br /&gt;
      }&lt;br /&gt;
      catch (Exception ex)&lt;br /&gt;
      {&lt;br /&gt;
        MessageBox.Show(ex.Message);&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      finally&lt;br /&gt;
      {&lt;br /&gt;
        reader.Close();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  private void btnSaveFile_Click(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    SaveFileDialog sfd = new SaveFileDialog();&lt;br /&gt;
    sfd.InitialDirectory = @&amp;quot;c:\&amp;quot;;&lt;br /&gt;
    sfd.Filter = &amp;quot;Text files (*.txt)|*.txt|&amp;quot; +&lt;br /&gt;
            &amp;quot;All files (*.*)|*.*&amp;quot;;&lt;br /&gt;
    sfd.FilterIndex = 1;              //  1 based index&lt;br /&gt;
    if (strFileName != null)&lt;br /&gt;
      sfd.FileName = strFileName;&lt;br /&gt;
    else&lt;br /&gt;
      sfd.FileName = &amp;quot;*.txt&amp;quot;;&lt;br /&gt;
    &lt;br /&gt;
    if (sfd.ShowDialog() == DialogResult.OK)&lt;br /&gt;
    {&lt;br /&gt;
      StreamWriter writer = new StreamWriter(strFileName,false);&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
        strFileName = sfd.FileName;&lt;br /&gt;
        writer.Write(txtFile.Text);&lt;br /&gt;
      }&lt;br /&gt;
      catch(Exception ex)&lt;br /&gt;
      {&lt;br /&gt;
        MessageBox.Show(ex.Message);&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
      finally&lt;br /&gt;
      {&lt;br /&gt;
        writer.Close();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  private void btnPageSetup_Click(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    PageSetupDialog psd = new PageSetupDialog();&lt;br /&gt;
    psd.Document = printDocument;&lt;br /&gt;
    psd.ShowDialog();&lt;br /&gt;
  }&lt;br /&gt;
  private void btnPrint_Click(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    PrintDialog pdlg = new PrintDialog();&lt;br /&gt;
    pdlg.Document = printDocument;&lt;br /&gt;
    &lt;br /&gt;
    if (pdlg.ShowDialog() == DialogResult.OK)&lt;br /&gt;
    {&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
        printDocument.Print();&lt;br /&gt;
      }&lt;br /&gt;
      catch(Exception ex)&lt;br /&gt;
      {&lt;br /&gt;
        MessageBox.Show(&amp;quot;Print error: &amp;quot; + ex.Message);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  private void btnPrintPreview_Click(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    PrintDialog ppdlg = new PrintDialog();&lt;br /&gt;
    ppdlg.Document = printDocument;&lt;br /&gt;
    ppdlg.ShowDialog();&lt;br /&gt;
  }&lt;br /&gt;
  private void pdPrintPage(object sender, PrintPageEventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    float linesPerPage = 0;&lt;br /&gt;
    float verticalOffset = 0;&lt;br /&gt;
    float leftMargin = e.MarginBounds.Left;&lt;br /&gt;
    float topMargin = e.MarginBounds.Top;&lt;br /&gt;
    int linesPrinted = 0;&lt;br /&gt;
    String strLine = null;&lt;br /&gt;
    linesPerPage = e.MarginBounds.Height / currentFont.GetHeight(e.Graphics);&lt;br /&gt;
    &lt;br /&gt;
    while (linesPrinted &amp;lt; linesPerPage &amp;amp;&amp;amp;&lt;br /&gt;
        ((strLine = stringReader.ReadLine())!= null ))&lt;br /&gt;
    {&lt;br /&gt;
      verticalOffset = topMargin + (linesPrinted * currentFont.GetHeight(e.Graphics));&lt;br /&gt;
      e.Graphics.DrawString(strLine, currentFont, Brushes.Black, leftMargin, verticalOffset);&lt;br /&gt;
      linesPrinted++;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    if (strLine != null)&lt;br /&gt;
      e.HasMorePages = true;&lt;br /&gt;
    else&lt;br /&gt;
      e.HasMorePages = false;&lt;br /&gt;
      &lt;br /&gt;
  }&lt;br /&gt;
  private void pdBeginPrint(object sender, PrintEventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    stringReader = new StringReader(txtFile.Text);&lt;br /&gt;
    currentFont = txtFile.Font;&lt;br /&gt;
  }&lt;br /&gt;
  private void pdEndPrint(object sender, PrintEventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    stringReader.Close();&lt;br /&gt;
    MessageBox.Show(&amp;quot;Done printing.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Prompt PrintDialog==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Drawing.Printing;&lt;br /&gt;
public class PrintDialogPrint : Form&lt;br /&gt;
{&lt;br /&gt;
    public PrintDialogPrint()&lt;br /&gt;
    {&lt;br /&gt;
        this.cmdPrint = new System.Windows.Forms.Button();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        // &lt;br /&gt;
        this.cmdPrint.Location = new System.Drawing.Point(109, 122);&lt;br /&gt;
        this.cmdPrint.Size = new System.Drawing.Size(75, 23);&lt;br /&gt;
        this.cmdPrint.Text = &amp;quot;Print&amp;quot;;&lt;br /&gt;
        this.cmdPrint.UseVisualStyleBackColor = true;&lt;br /&gt;
        this.cmdPrint.Click += new System.EventHandler(this.cmdPrint_Click);&lt;br /&gt;
        // &lt;br /&gt;
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);&lt;br /&gt;
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;&lt;br /&gt;
        this.ClientSize = new System.Drawing.Size(272, 260);&lt;br /&gt;
        this.Controls.Add(this.cmdPrint);&lt;br /&gt;
        this.Text = &amp;quot;Simple Print&amp;quot;;&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
    private void cmdPrint_Click(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        PrintDocument doc = new PrintDocument();&lt;br /&gt;
        doc.PrintPage += this.Doc_PrintPage;&lt;br /&gt;
        PrintDialog dlgSettings = new PrintDialog();&lt;br /&gt;
        dlgSettings.Document = doc;&lt;br /&gt;
        if (dlgSettings.ShowDialog() == DialogResult.OK)&lt;br /&gt;
        {&lt;br /&gt;
            doc.Print();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    private void Doc_PrintPage(object sender, PrintPageEventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        Font font = new Font(&amp;quot;Arial&amp;quot;, 30);&lt;br /&gt;
        &lt;br /&gt;
        float x = e.MarginBounds.Left;&lt;br /&gt;
        float y = e.MarginBounds.Top;&lt;br /&gt;
        float lineHeight = font.GetHeight(e.Graphics);&lt;br /&gt;
        for (int i = 0; i &amp;lt; 5; i++)&lt;br /&gt;
        {&lt;br /&gt;
            e.Graphics.DrawString(&amp;quot;This is line &amp;quot; + i.ToString(),font, Brushes.Black, x, y);&lt;br /&gt;
            y += lineHeight;&lt;br /&gt;
        }&lt;br /&gt;
        y += lineHeight;&lt;br /&gt;
        e.Graphics.DrawImage(Image.FromFile(&amp;quot;c:\\YourFile.bmp&amp;quot;), x, y);&lt;br /&gt;
        &lt;br /&gt;
    }&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Application.EnableVisualStyles();&lt;br /&gt;
        Application.SetCompatibleTextRenderingDefault(false);&lt;br /&gt;
        Application.Run(new PrintDialogPrint());&lt;br /&gt;
    }&lt;br /&gt;
    private System.Windows.Forms.Button cmdPrint;&lt;br /&gt;
    &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>