using System.Text;
public class Form1 : System.Windows.Forms.Form
{
string strbody;
#region " Windows Form Designer generated code "
public Form1() : base()
{
//This call is required by the Windows Form Designer.
//Add any initialization after the InitializeComponent() call
InitializeComponent();
}
//Form overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing) {
if ((components != null)) {
components.Dispose();
}
}
base.Dispose(disposing);
}
//Required by the Windows Form Designer
private System.ComponentModel.IContainer components;
//NOTE: The following procedure is required by the Windows Form Designer
//It can be modified using the Windows Form Designer.
//Do not modify it using the code editor.
internal RichTextBoxPrintCtrl RichTextBox1;
internal System.Windows.Forms.MainMenu MainMenu1;
internal System.Windows.Forms.MenuItem MenuItem1;
internal System.Windows.Forms.MenuItem MenuItem2;
internal System.Windows.Forms.MenuItem MenuItem3;
internal System.Windows.Forms.MenuItem MenuItem4;
internal System.Drawing.Printing.PrintDocument PrintDocument1;
internal System.Windows.Forms.PrintPreviewDialog PrintPreviewDialog1;
internal System.Windows.Forms.MenuItem MenuItem5;
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.RichTextBox1 = new TarzNigar2.RichTextBoxPrintCtrl();
this.MainMenu1 = new System.Windows.Forms.MainMenu();
this.MenuItem1 = new System.Windows.Forms.MenuItem();
this.MenuItem2 = new System.Windows.Forms.MenuItem();
this.MenuItem3 = new System.Windows.Forms.MenuItem();
this.MenuItem4 = new System.Windows.Forms.MenuItem();
this.PrintDocument1 = new System.Drawing.Printing.PrintDocument();
this.PrintPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
this.MenuItem5 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
//RichTextBox1
//
this.RichTextBox1.Location = new System.Drawing.Point(0, 0);
this.RichTextBox1.Name = "RichTextBox1";
this.RichTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.RichTextBox1.Size = new System.Drawing.Size(296, 272);
this.RichTextBox1.TabIndex = 0;
this.RichTextBox1.Text = "";
//
//MainMenu1
//
this.MainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.MenuItem1, this.MenuItem3 });
//
//MenuItem1
//
this.MenuItem1.Index = 0;
this.MenuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.MenuItem2, this.MenuItem5 });
this.MenuItem1.Text = "&Edit";
//
//MenuItem2
//
this.MenuItem2.Index = 0;
this.MenuItem2.Text = "Bold";
//
//MenuItem3
//
this.MenuItem3.Index = 1;
this.MenuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.MenuItem4 });
this.MenuItem3.Text = "&File";
//
//MenuItem4
//
this.MenuItem4.Index = 0;
this.MenuItem4.Text = "Print Preview";
//
//PrintDocument1
//
//
//PrintPreviewDialog1
//
this.PrintPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.PrintPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.PrintPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.PrintPreviewDialog1.Document = this.PrintDocument1;
this.PrintPreviewDialog1.Enabled = true;
this.PrintPreviewDialog1.Icon = (System.Drawing.Icon)resources.GetObject("PrintPreviewDialog1.Icon");
this.PrintPreviewDialog1.Location = new System.Drawing.Point(256, 17);
this.PrintPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
this.PrintPreviewDialog1.Name = "PrintPreviewDialog1";
this.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
this.PrintPreviewDialog1.Visible = false;
//
//MenuItem5
//
this.MenuItem5.Index = 1;
this.MenuItem5.Text = "Font 16";
//
//Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.RichTextBox1);
this.Menu = this.MainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private void // ERROR: Handles clauses are not supported in C#
MenuItem2_Click(System.Object sender, System.EventArgs e)
{
if ((RichTextBox1.SelectionFont != null)) {
System.Drawing.Font currentFont = RichTextBox1.SelectionFont;
System.Drawing.FontStyle newFontStyle = default(System.Drawing.FontStyle);
if (RichTextBox1.SelectionFont.Bold == true) {
newFontStyle = FontStyle.Regular;
}
else {
newFontStyle = FontStyle.Bold;
}
RichTextBox1.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
}
}
#region "Printing"
private int m_nFirstCharOnPage;
private int lastcharOnPage;
private void // ERROR: Handles clauses are not supported in C#
PrintDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
// Start at the beginning of the text
m_nFirstCharOnPage = 0;
}
private void // ERROR: Handles clauses are not supported in C#
PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font fnt = RichTextBox1.SelectionFont;
int lm = 0;
int rm = 0;
int tm = 0;
int bm = 0;
{
lm = PrintDocument1.DefaultPageSettings.Margins.Left;
rm = PrintDocument1.DefaultPageSettings.Margins.Right;
tm = PrintDocument1.DefaultPageSettings.Margins.Top - 5;
bm = PrintDocument1.DefaultPageSettings.Margins.Bottom - 5;
}
int pwidth = 0;
int pheight = 0;
{
pwidth = PrintDocument1.DefaultPageSettings.PaperSize.Width - lm - rm;
pheight = PrintDocument1.DefaultPageSettings.PaperSize.Height - tm - bm;
}
e.Graphics.DrawRectangle(Pens.Blue, lm - 3, tm - 2, pwidth + 5, pheight + 5);
RectangleF drawRect = new RectangleF(lm, tm, pwidth, pheight);
StringFormat drawFormat = new StringFormat(StringFormatFlags.DirectionRightToLeft);
drawFormat.Alignment = StringAlignment.Near;
lastcharOnPage = RichTextBox1.FormatRange(false, e, m_nFirstCharOnPage, RichTextBox1.TextLength);
int charToGet = 0;
if (lastcharOnPage < RichTextBox1.TextLength) {
charToGet = lastcharOnPage - m_nFirstCharOnPage - 1;
}
else {
charToGet = RichTextBox1.TextLength - m_nFirstCharOnPage;
}
string PageText = RichTextBox1.Text.Substring(m_nFirstCharOnPage, charToGet);
e.Graphics.DrawString(PageText, fnt, Brushes.Black, drawRect, drawFormat);
m_nFirstCharOnPage = lastcharOnPage;
if (m_nFirstCharOnPage < RichTextBox1.TextLength) {
e.HasMorePages = true;
}
else {
e.HasMorePages = false;
}
}
private void // ERROR: Handles clauses are not supported in C#
PrintDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
// Clean up cached information
RichTextBox1.FormatRangeDone();
}
#endregion
private void // ERROR: Handles clauses are not supported in C#
MenuItem4_Click(System.Object sender, System.EventArgs e)
{
try {
PrintPreviewDialog1.Document = PrintDocument1;
PrintPreviewDialog1.RightToLeft = RightToLeft.Yes;
PrintPreviewDialog1.ShowDialog();
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
// (((((((((((((( Unicode to UTF-8 Convert function ))))))))))
public string GetStringFromUnicode(params int[] codes)
{
System.Text.StringBuilder bldr = new System.Text.StringBuilder();
foreach (int code in codes) {
bldr.Append(Convert.ToChar(code));
}
return bldr.ToString();
}
private void // ERROR: Handles clauses are not supported in C#
richTextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
switch (e.KeyChar) {
case Strings.Chr(32):
//space
e.Handled = true;
RichTextBox1.SelectedText = " ";
break;
case Strings.Chr(97):
//a
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x627);
break;
case Strings.Chr(65):
//A
RichTextBox1.SelectedText = Strings.ChrW(0x622);
e.Handled = true;
break;
case Strings.Chr(98):
//b
RichTextBox1.SelectedText = Strings.ChrW(0x628);
e.Handled = true;
break;
case Strings.Chr(66):
//B
RichTextBox1.SelectedText = Strings.ChrW(0x625);
e.Handled = true;
break;
case Strings.Chr(99):
//c
RichTextBox1.SelectedText = Strings.ChrW(0x686);
e.Handled = true;
break;
case Strings.Chr(67):
//C
RichTextBox1.SelectedText = Strings.ChrW(0x62b);
e.Handled = true;
break;
case Strings.Chr(100):
//d
RichTextBox1.SelectedText = Strings.ChrW(0x62f);
e.Handled = true;
break;
case Strings.Chr(68):
//D
RichTextBox1.SelectedText = Strings.ChrW(0x688);
e.Handled = true;
break;
case Strings.Chr(101):
//e
RichTextBox1.SelectedText = Strings.ChrW(0x639);
e.Handled = true;
break;
case Strings.Chr(69):
//E
RichTextBox1.SelectedText = Strings.ChrW(0x13c);
e.Handled = true;
break;
case Strings.Chr(102):
//f
RichTextBox1.SelectedText = Strings.ChrW(0x641);
e.Handled = true;
break;
case Strings.Chr(70):
//F
RichTextBox1.SelectedText = Strings.ChrW(0x13f);
e.Handled = true;
break;
case Strings.Chr(103):
//g
RichTextBox1.SelectedText = Strings.ChrW(0x6af);
e.Handled = true;
break;
case Strings.Chr(71):
//G
RichTextBox1.SelectedText = Strings.ChrW(0x63a);
e.Handled = true;
break;
case Strings.Chr(104):
//h
RichTextBox1.SelectedText = Strings.ChrW(0x647);
e.Handled = true;
break;
case Strings.Chr(72):
//H
RichTextBox1.SelectedText = Strings.ChrW(0x62d);
e.Handled = true;
break;
case Strings.Chr(105):
//i
RichTextBox1.SelectedText = Strings.ChrW(0x649);
e.Handled = true;
break;
case Strings.Chr(73):
//I
RichTextBox1.SelectedText = Strings.ChrW(0x64a);
e.Handled = true;
break;
case Strings.Chr(106):
//j
RichTextBox1.SelectedText = Strings.ChrW(0x62c);
e.Handled = true;
break;
case Strings.Chr(74):
//J
RichTextBox1.SelectedText = Strings.ChrW(0x636);
e.Handled = true;
break;
case Strings.Chr(107):
//k
RichTextBox1.SelectedText = Strings.ChrW(0x6a9);
e.Handled = true;
break;
case Strings.Chr(75):
//K
RichTextBox1.SelectedText = Strings.ChrW(0x62e);
e.Handled = true;
break;
case Strings.Chr(108):
//l
RichTextBox1.SelectedText = Strings.ChrW(0x644);
e.Handled = true;
break;
case Strings.Chr(76):
//L
RichTextBox1.SelectedText = Strings.ChrW(0x13e);
e.Handled = true;
break;
case Strings.Chr(109):
//m
RichTextBox1.SelectedText = Strings.ChrW(0x645);
e.Handled = true;
break;
case Strings.Chr(77):
//M
RichTextBox1.SelectedText = Strings.ChrW(0xfdfa);
e.Handled = true;
break;
case Strings.Chr(110):
//n
RichTextBox1.SelectedText = Strings.ChrW(0x646);
e.Handled = true;
break;
case Strings.Chr(78):
//N
RichTextBox1.SelectedText = Strings.ChrW(0x6ba);
e.Handled = true;
break;
case Strings.Chr(111):
//o
RichTextBox1.SelectedText = Strings.ChrW(0x6c1);
e.Handled = true;
break;
//richTextBox1.selectedtext = ChrW(&H647)
case Strings.Chr(79):
//O
RichTextBox1.SelectedText = Strings.ChrW(0x629);
e.Handled = true;
break;
case Strings.Chr(112):
//p
RichTextBox1.SelectedText = Strings.ChrW(0x67e);
e.Handled = true;
break;
case Strings.Chr(80):
//P
RichTextBox1.SelectedText = Strings.ChrW(0x64f);
e.Handled = true;
break;
case Strings.Chr(113):
//q
RichTextBox1.SelectedText = Strings.ChrW(0x642);
e.Handled = true;
break;
case Strings.Chr(81):
//Q
RichTextBox1.SelectedText = Strings.ChrW(0x64e);
e.Handled = true;
break;
case Strings.Chr(114):
//r
RichTextBox1.SelectedText = Strings.ChrW(0x631);
e.Handled = true;
break;
case Strings.Chr(82):
//R
RichTextBox1.SelectedText = Strings.ChrW(0x691);
e.Handled = true;
break;
case Strings.Chr(115):
//s
RichTextBox1.SelectedText = Strings.ChrW(0x633);
e.Handled = true;
break;
case Strings.Chr(83):
//S
RichTextBox1.SelectedText = Strings.ChrW(0x635);
e.Handled = true;
break;
case Strings.Chr(116):
//t
RichTextBox1.SelectedText = Strings.ChrW(0x62a);
e.Handled = true;
break;
case Strings.Chr(84):
//T
RichTextBox1.SelectedText = Strings.ChrW(0x679);
e.Handled = true;
break;
case Strings.Chr(117):
//u
RichTextBox1.SelectedText = Strings.ChrW(0x621);
e.Handled = true;
break;
case Strings.Chr(85):
//U
RichTextBox1.SelectedText = Strings.ChrW(0x674);
e.Handled = true;
break;
case Strings.Chr(118):
//v
RichTextBox1.SelectedText = Strings.ChrW(0x637);
e.Handled = true;
break;
case Strings.Chr(86):
//V
RichTextBox1.SelectedText = Strings.ChrW(0x638);
e.Handled = true;
break;
case Strings.Chr(119):
//w
RichTextBox1.SelectedText = Strings.ChrW(0x648);
e.Handled = true;
break;
case Strings.Chr(87):
//W
RichTextBox1.SelectedText = Strings.ChrW(0x64c);
e.Handled = true;
break;
case Strings.Chr(120):
//x
RichTextBox1.SelectedText = Strings.ChrW(0x634);
e.Handled = true;
break;
case Strings.Chr(88):
//X
RichTextBox1.SelectedText = Strings.ChrW(0x698);
e.Handled = true;
break;
case Strings.Chr(121):
//y
RichTextBox1.SelectedText = Strings.ChrW(0x6d2);
e.Handled = true;
break;
case Strings.Chr(89):
//Y
RichTextBox1.SelectedText = Strings.ChrW(0x6d3);
e.Handled = true;
break;
case Strings.Chr(122):
//z
RichTextBox1.SelectedText = Strings.ChrW(0x630);
e.Handled = true;
break;
case Strings.Chr(90):
//Z
RichTextBox1.SelectedText = Strings.ChrW(0x632);
e.Handled = true;
break;
case Strings.Chr(45):
//-
RichTextBox1.SelectedText = Strings.ChrW(0x650);
e.Handled = true;
break;
case Strings.Chr(95):
//_
RichTextBox1.SelectedText = Strings.ChrW(0x64e);
e.Handled = true;
break;
case Strings.Chr(63):
//?
RichTextBox1.SelectedText = Strings.ChrW(0x61f);
e.Handled = true;
break;
case Strings.Chr(60):
//<
RichTextBox1.SelectedText = Strings.ChrW(0x64d);
e.Handled = true;
break;
case Strings.Chr(62):
//>
RichTextBox1.SelectedText = Strings.ChrW(0x64b);
e.Handled = true;
break;
case Strings.Chr(44):
//, comma
RichTextBox1.SelectedText = Strings.ChrW(0x60c);
e.Handled = true;
break;
case Strings.Chr(59):
//; semi-colon
RichTextBox1.SelectedText = Strings.ChrW(0x61b);
e.Handled = true;
break;
case Strings.Chr(96):
//' shadda
RichTextBox1.SelectedText = Strings.ChrW(0x651);
e.Handled = true;
break;
case Strings.Chr(126):
// ~ dammatan
RichTextBox1.SelectedText = Strings.ChrW(0x64c);
e.Handled = true;
break;
case Strings.Chr(43):
//+ madda
RichTextBox1.SelectedText = Strings.ChrW(0x6e4);
e.Handled = true;
break;
case Strings.Chr(46):
//. Tahweel
RichTextBox1.SelectedText = Strings.ChrW(0x640);
e.Handled = true;
break;
case Strings.Chr(59):
//;
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x61b);
break;
case Strings.Chr(42):
//*
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x66d);
break;
case Strings.Chr(48):
//0
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x660);
break;
case Strings.Chr(49):
//1
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x661);
break;
case Strings.Chr(50):
//2
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x662);
break;
case Strings.Chr(51):
//3
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x663);
break;
case Strings.Chr(52):
//4
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x664);
break;
case Strings.Chr(53):
//5
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x665);
break;
case Strings.Chr(54):
//6
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x666);
break;
case Strings.Chr(55):
//7
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x667);
break;
case Strings.Chr(56):
//8
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x668);
break;
case Strings.Chr(57):
//9
e.Handled = true;
RichTextBox1.SelectedText = Strings.ChrW(0x669);
break;
}
}
private void // ERROR: Handles clauses are not supported in C#
MenuItem5_Click(System.Object sender, System.EventArgs e)
{
RichTextBox1.SelectionFont = new Font("Arial", 16, FontStyle.Bold);
}
}