Print Dialog with Richtextbox
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Drawing.Text;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Drawing.Printing;
namespace
print_dialog_boxes
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
OpenFileDialog
ofdlg = new OpenFileDialog();
ofdlg.InitialDirectory = @"C:\";
ofdlg.RestoreDirectory = true;
ofdlg.Title = "Open Text Files";
ofdlg.DefaultExt = "txt";
ofdlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
ofdlg.FilterIndex = 2;
ofdlg.CheckFileExists = true;
ofdlg.CheckPathExists = true;
if
(ofdlg.ShowDialog() == DialogResult.OK)
{
richTextBox1.SelectionFont = new Font("Verdana", 12, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.LoadFile(ofdlg.FileName, RichTextBoxStreamType.PlainText);
this.Text
= ofdlg.FileName.ToString();
}
}
private
void button2_Click(object
sender, EventArgs e)
{
PrintDialog
printDlg = new PrintDialog();
PrintDocument
printDoc = new PrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
printDlg.ShowHelp= true;
printDlg.ShowNetwork = true;
printDlg.PrinterSettings =
printDoc.PrinterSettings;
if
(printDlg.ShowDialog() == DialogResult.OK)
{
printDoc.PrinterSettings =
printDlg.PrinterSettings;
printDoc.Print();
}
}
private
void button3_Click(object
sender, EventArgs e)
{
Form2
f2 = new Form2();
f2.Show();
}
}
}
export richtextbox in c#.net
ReplyDelete