using System;using System.Windows.Forms;using System.IO;using System.Drawing.Printing; namespace PrintTextBox{public partial class Form1 : Form{internal string MyFileName;internal bool newfile;internal bool open;public Form1(){InitializeComponent();this.Show();}private void richTextBox1_TextChanged(object sender, EventArgs e){}private void newToolStripMenuItem_Click(object sender, EventArgs e){this.richTextBox1.Clear();newfile = true;Text = "PrintTextBox";}private void opentoolStripMenu_Click(object sender, EventArgs e){try{OpenFileDialog dlgOpen = new OpenFileDialog();dlgOpen.DefaultExt = "Text files |*.txt";dlgOpen.Filter = "Text files |*.txt|RTF Files (*.rtf)|*.rtf|All files |*.*";dlgOpen.Multiselect = true;if (dlgOpen.ShowDialog() == DialogResult.OK){this.MyFileName = Text = dlgOpen.FileName; //Display and remember the open file name for savingStreamReader streamReader = new StreamReader(dlgOpen.FileName);this.richTextBox1.Text = streamReader.ReadToEnd();streamReader.Close();open = true; newfile = false;}}catch (ArgumentException) { }catch (IOException) { }catch (FormatException) { }finally { }}private void PrintoolStripMenut_Click(object sender, EventArgs e){PrintDialog dlgPrint = new PrintDialog();if (dlgPrint.ShowDialog() == DialogResult.OK){//Print a document or print the textboxPrintDocument printdoc = new PrintDocument();printdoc.DocumentName = "MyDocument.txt";printdoc.Print(); //Prints an empty page!!!!//// or print the richTextBox ????//}}private void PreviewtoolStripMenu_Click(object sender, EventArgs e){PrintPreviewDialog dlgPreview = new PrintPreviewDialog();if (dlgPreview.ShowDialog() == DialogResult.OK){//same problem as print.}}private void ExittoolStripMenu_Click(object sender, EventArgs e){Application.Exit();}}}