<?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%2FC_Sharp_by_API%2FSystem.Windows.Forms%2FPrintDialog</id>
		<title>Csharp/C Sharp by API/System.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%2FC_Sharp_by_API%2FSystem.Windows.Forms%2FPrintDialog"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp_by_API/System.Windows.Forms/PrintDialog&amp;action=history"/>
		<updated>2026-04-30T13:44:32Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp_by_API/System.Windows.Forms/PrintDialog&amp;diff=4088&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp_by_API/System.Windows.Forms/PrintDialog&amp;diff=4088&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:35Z</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/C_Sharp_by_API/System.Windows.Forms/PrintDialog&amp;diff=4089&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp_by_API/System.Windows.Forms/PrintDialog&amp;diff=4089&amp;oldid=prev"/>
				<updated>2010-05-26T12:09:12Z</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;==new PrintDialog()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Code revised from chapter 7&lt;br /&gt;
&lt;br /&gt;
GDI+ Custom Controls with Visual C# 2005&lt;br /&gt;
By Iulian Serban, Dragos Brezoi, Tiberiu Radu, Adam Ward &lt;br /&gt;
Language English&lt;br /&gt;
Paperback 272 pages [191mm x 235mm]&lt;br /&gt;
Release date July 2006&lt;br /&gt;
ISBN 1904811604&lt;br /&gt;
Sample chapter&lt;br /&gt;
http://www.packtpub.ru/files/1604_CustomControls_SampleChapter.pdf&lt;br /&gt;
&lt;br /&gt;
For More info on GDI+ Custom Control with Microsoft Visual C# book &lt;br /&gt;
visit website www.packtpub.ru &lt;br /&gt;
*/ &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Drawing.Printing;&lt;br /&gt;
namespace PrintingCustomControlApp1&lt;br /&gt;
{&lt;br /&gt;
    public partial class Form1 : Form&lt;br /&gt;
    {&lt;br /&gt;
        public Form1()&lt;br /&gt;
        {&lt;br /&gt;
            InitializeComponent();&lt;br /&gt;
        }&lt;br /&gt;
        private void button1_Click(object sender, EventArgs e)&lt;br /&gt;
        {&lt;br /&gt;
            printableRichTextBox1.Print(false);&lt;br /&gt;
        }&lt;br /&gt;
        private System.ruponentModel.IContainer components = null;&lt;br /&gt;
        /// &amp;lt;summary&amp;gt;&lt;br /&gt;
        /// Clean up any resources being used.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        /// &amp;lt;param name=&amp;quot;disposing&amp;quot;&amp;gt;true if managed resources should be disposed; otherwise, false.&amp;lt;/param&amp;gt;&lt;br /&gt;
        protected override void Dispose(bool disposing)&lt;br /&gt;
        {&lt;br /&gt;
            if (disposing &amp;amp;&amp;amp; (components != null))&lt;br /&gt;
            {&lt;br /&gt;
                components.Dispose();&lt;br /&gt;
            }&lt;br /&gt;
            base.Dispose(disposing);&lt;br /&gt;
        }&lt;br /&gt;
        #region Windows Form Designer generated code&lt;br /&gt;
        /// &amp;lt;summary&amp;gt;&lt;br /&gt;
        /// Required method for Designer support - do not modify&lt;br /&gt;
        /// the contents of this method with the code editor.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        private void InitializeComponent()&lt;br /&gt;
        {&lt;br /&gt;
            this.printableRichTextBox1 = new PrintingCustomControlApp1.PrintableRichTextBox();&lt;br /&gt;
            this.button1 = new System.Windows.Forms.Button();&lt;br /&gt;
            this.SuspendLayout();&lt;br /&gt;
            // &lt;br /&gt;
            // printableRichTextBox1&lt;br /&gt;
            // &lt;br /&gt;
            this.printableRichTextBox1.Location = new System.Drawing.Point(77, 25);&lt;br /&gt;
            this.printableRichTextBox1.Name = &amp;quot;printableRichTextBox1&amp;quot;;&lt;br /&gt;
            this.printableRichTextBox1.Size = new System.Drawing.Size(124, 117);&lt;br /&gt;
            this.printableRichTextBox1.TabIndex = 0;&lt;br /&gt;
            this.printableRichTextBox1.Text = &amp;quot;&amp;quot;;&lt;br /&gt;
            // &lt;br /&gt;
            // button1&lt;br /&gt;
            // &lt;br /&gt;
            this.button1.Location = new System.Drawing.Point(63, 191);&lt;br /&gt;
            this.button1.Name = &amp;quot;button1&amp;quot;;&lt;br /&gt;
            this.button1.Size = new System.Drawing.Size(126, 30);&lt;br /&gt;
            this.button1.TabIndex = 1;&lt;br /&gt;
            this.button1.Text = &amp;quot;Print the Control text&amp;quot;;&lt;br /&gt;
            this.button1.UseVisualStyleBackColor = true;&lt;br /&gt;
            this.button1.Click += new System.EventHandler(this.button1_Click);&lt;br /&gt;
            // &lt;br /&gt;
            // Form1&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(292, 266);&lt;br /&gt;
            this.Controls.Add(this.button1);&lt;br /&gt;
            this.Controls.Add(this.printableRichTextBox1);&lt;br /&gt;
            this.Name = &amp;quot;Form1&amp;quot;;&lt;br /&gt;
            this.Text = &amp;quot;Form1&amp;quot;;&lt;br /&gt;
            this.ResumeLayout(false);&lt;br /&gt;
        }&lt;br /&gt;
        #endregion&lt;br /&gt;
        private PrintableRichTextBox printableRichTextBox1;&lt;br /&gt;
        private System.Windows.Forms.Button button1;&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 Form1());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public partial class PrintableRichTextBox : RichTextBox&lt;br /&gt;
    {&lt;br /&gt;
        public PrintableRichTextBox()&lt;br /&gt;
        {&lt;br /&gt;
            InitializeComponent();&lt;br /&gt;
            _prtdoc = new PrintDocument();&lt;br /&gt;
            _prtdoc.PrintPage += new PrintPageEventHandler(_prtdoc_PrintPage);&lt;br /&gt;
        }&lt;br /&gt;
        string _text = null;&lt;br /&gt;
        int _pageNumber = 0;&lt;br /&gt;
        int _start = 0;&lt;br /&gt;
        PrintDocument _prtdoc = null;&lt;br /&gt;
        private bool DrawText(Graphics target, Graphics measurer, RectangleF r, Brush brsh)&lt;br /&gt;
        {&lt;br /&gt;
            if (r.Height &amp;lt; this.Font.Height)&lt;br /&gt;
                throw new ArgumentException(&amp;quot;The rectangle is not tall enough to fit a single line of text inside.&amp;quot;);&lt;br /&gt;
            int charsFit = 0;&lt;br /&gt;
            int linesFit = 0;&lt;br /&gt;
            int cut = 0;&lt;br /&gt;
            string temp = _text.Substring(_start);&lt;br /&gt;
            StringFormat format = new StringFormat(StringFormatFlags.FitBlackBox | StringFormatFlags.LineLimit);&lt;br /&gt;
            //measure how much of the string we can fit into the rectangle&lt;br /&gt;
            measurer.MeasureString(temp, this.Font, r.Size, format, out charsFit, out linesFit);&lt;br /&gt;
            cut = BreakText(temp, charsFit);&lt;br /&gt;
            if (cut != charsFit)&lt;br /&gt;
                temp = temp.Substring(0, cut);&lt;br /&gt;
            bool h = true;&lt;br /&gt;
            h &amp;amp;= true;&lt;br /&gt;
            target.DrawString(temp.Trim(&amp;quot; &amp;quot;), this.Font, brsh, r, format);&lt;br /&gt;
            _start += cut;&lt;br /&gt;
            if (_start == _text.Length)&lt;br /&gt;
            {&lt;br /&gt;
                _start = 0; //reset the location so we can repeat the document&lt;br /&gt;
                return true; //finished printing&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
                return false;&lt;br /&gt;
        }&lt;br /&gt;
        private static int BreakText(string text, int approx)&lt;br /&gt;
        {&lt;br /&gt;
            if (approx == 0)&lt;br /&gt;
                throw new ArgumentException();&lt;br /&gt;
            if (approx &amp;lt; text.Length)&lt;br /&gt;
            {&lt;br /&gt;
                //are we in the middle of a word?&lt;br /&gt;
                if (char.IsLetterOrDigit(text[approx]) &amp;amp;&amp;amp; char.IsLetterOrDigit(text[approx - 1]))&lt;br /&gt;
                {&lt;br /&gt;
                    int temp = text.LastIndexOf(&amp;quot; &amp;quot;, approx, approx + 1);&lt;br /&gt;
                    if (temp &amp;gt;= 0)&lt;br /&gt;
                        return temp;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            return approx;&lt;br /&gt;
        }&lt;br /&gt;
        public void Print(bool hardcopy)&lt;br /&gt;
        {&lt;br /&gt;
            _text = this.Text;&lt;br /&gt;
            //create a PrintDialog based on the PrintDocument&lt;br /&gt;
            PrintDialog pdlg = new PrintDialog();&lt;br /&gt;
            pdlg.Document = _prtdoc;&lt;br /&gt;
            //show the PrintDialog&lt;br /&gt;
            if (pdlg.ShowDialog() == DialogResult.OK)&lt;br /&gt;
            {&lt;br /&gt;
                //create a PageSetupDialog based on the PrintDocument and PrintDialog&lt;br /&gt;
                PageSetupDialog psd = new PageSetupDialog();&lt;br /&gt;
                psd.EnableMetric = true; //Ensure all dialog measurements are in metric&lt;br /&gt;
                psd.Document = pdlg.Document;&lt;br /&gt;
                //show the PageSetupDialog&lt;br /&gt;
                if (psd.ShowDialog() == DialogResult.OK)&lt;br /&gt;
                {&lt;br /&gt;
                    //apply the settings of both dialogs&lt;br /&gt;
                    _prtdoc.DefaultPageSettings = psd.PageSettings;&lt;br /&gt;
                    //decide what action to take&lt;br /&gt;
                    if (hardcopy)&lt;br /&gt;
                    {&lt;br /&gt;
                        //actually print hardcopy&lt;br /&gt;
                        _prtdoc.Print();&lt;br /&gt;
                    }&lt;br /&gt;
                    else&lt;br /&gt;
                    {&lt;br /&gt;
                        //preview onscreen instead&lt;br /&gt;
                        PrintPreviewDialog prvw = new PrintPreviewDialog();&lt;br /&gt;
                        prvw.Document = _prtdoc;&lt;br /&gt;
                        prvw.ShowDialog();&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private void _prtdoc_PrintPage(object sender, PrintPageEventArgs e)&lt;br /&gt;
        {&lt;br /&gt;
            e.Graphics.Clip = new Region(e.MarginBounds);&lt;br /&gt;
            //this method does all our printing work&lt;br /&gt;
            Single x = e.MarginBounds.Left;&lt;br /&gt;
            Single y = e.MarginBounds.Top;&lt;br /&gt;
            if (_pageNumber++ == 0)&lt;br /&gt;
                y += 30;&lt;br /&gt;
            RectangleF mainTextArea = RectangleF.FromLTRB(x, y, e.MarginBounds.Right, e.MarginBounds.Bottom);&lt;br /&gt;
            //draw the text&lt;br /&gt;
            if (DrawText(e.Graphics, e.PageSettings.PrinterSettings.CreateMeasurementGraphics(), mainTextArea, Brushes.Black))&lt;br /&gt;
            {&lt;br /&gt;
                e.HasMorePages = false; //the end has been reached&lt;br /&gt;
                _pageNumber = 0;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
                e.HasMorePages = true;&lt;br /&gt;
        }&lt;br /&gt;
        private System.ruponentModel.IContainer components = null;&lt;br /&gt;
        /// &amp;lt;summary&amp;gt; &lt;br /&gt;
        /// Clean up any resources being used.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        /// &amp;lt;param name=&amp;quot;disposing&amp;quot;&amp;gt;true if managed resources should be disposed; otherwise, false.&amp;lt;/param&amp;gt;&lt;br /&gt;
        protected override void Dispose(bool disposing)&lt;br /&gt;
        {&lt;br /&gt;
            if (disposing &amp;amp;&amp;amp; (components != null))&lt;br /&gt;
            {&lt;br /&gt;
                components.Dispose();&lt;br /&gt;
            }&lt;br /&gt;
            base.Dispose(disposing);&lt;br /&gt;
        }&lt;br /&gt;
        #region Component Designer generated code&lt;br /&gt;
        /// &amp;lt;summary&amp;gt; &lt;br /&gt;
        /// Required method for Designer support - do not modify &lt;br /&gt;
        /// the contents of this method with the code editor.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        private void InitializeComponent()&lt;br /&gt;
        {&lt;br /&gt;
            components = new System.ruponentModel.Container();&lt;br /&gt;
            //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;&lt;br /&gt;
        }&lt;br /&gt;
        #endregion&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==PrintDialog.Document==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&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;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>