Пример #1
0
        private void PrintMenu_Click(object sender, EventArgs e)
        {
            StringReader streamToPrint = new StringReader(textArea.Text);

            //Assumes the default printer
            TextPrintDocument pd = new TextPrintDocument(streamToPrint, textArea.Font);

            if (storedPageSettings != null)
            {
                pd.DefaultPageSettings = storedPageSettings;
            }

            PrintDialog dlg = new PrintDialog();

            dlg.Document = pd;
            DialogResult result = dlg.ShowDialog();

            if (result == DialogResult.OK)
            {
                pd.Print();
            }
        }
Пример #2
0
        private void PrintPreviewMenu_Click(object sender, EventArgs e)
        {
            try
            {
                StringReader streamToPrint = new StringReader(textArea.Text);

                //Assumes the default printer
                TextPrintDocument pd = new TextPrintDocument(streamToPrint, textArea.Font);

                if (storedPageSettings != null)
                {
                    pd.DefaultPageSettings = storedPageSettings;
                }

                PrintPreviewDialog dlg = new PrintPreviewDialog();
                dlg.Document = pd;
                dlg.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred attempting to preview the file to print - " + ex.Message);
            }
        }