Custom "RichTextBox" replaced to common "RichTextBox"

This commit is contained in:
Alexander 2019-08-22 20:55:56 +03:00
parent 739c3e049e
commit d9271d947b
2 changed files with 154 additions and 159 deletions

View file

@ -102,8 +102,8 @@ public void InitializeComponent()
this.FileLocationToolbarButton = new System.Windows.Forms.PictureBox(); this.FileLocationToolbarButton = new System.Windows.Forms.PictureBox();
this.SaveToolBarButton = new System.Windows.Forms.PictureBox(); this.SaveToolBarButton = new System.Windows.Forms.PictureBox();
this.OpenToolbarButton = new System.Windows.Forms.PictureBox(); this.OpenToolbarButton = new System.Windows.Forms.PictureBox();
this.CustomRTB = new Crypto_Notepad.CustomRichTextBox();
this.LineNumbers_For_RichTextBox = new LineNumbers.LineNumbers_For_RichTextBox(); this.LineNumbers_For_RichTextBox = new LineNumbers.LineNumbers_For_RichTextBox();
this.RichTextBox = new System.Windows.Forms.RichTextBox();
this.MainMenu.SuspendLayout(); this.MainMenu.SuspendLayout();
this.EditorMenuStrip.SuspendLayout(); this.EditorMenuStrip.SuspendLayout();
this.SearchPanel.SuspendLayout(); this.SearchPanel.SuspendLayout();
@ -858,27 +858,6 @@ public void InitializeComponent()
this.OpenToolbarButton.TabStop = false; this.OpenToolbarButton.TabStop = false;
this.OpenToolbarButton.Click += new System.EventHandler(this.OpenToolbarButton_Click); this.OpenToolbarButton.Click += new System.EventHandler(this.OpenToolbarButton_Click);
// //
// CustomRTB
//
this.CustomRTB.AcceptsTab = true;
this.CustomRTB.BackColor = System.Drawing.SystemColors.Window;
this.CustomRTB.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.CustomRTB.ContextMenuStrip = this.EditorMenuStrip;
this.CustomRTB.Dock = System.Windows.Forms.DockStyle.Fill;
this.CustomRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
this.CustomRTB.ForeColor = System.Drawing.SystemColors.WindowText;
this.CustomRTB.Location = new System.Drawing.Point(17, 47);
this.CustomRTB.Name = "CustomRTB";
this.CustomRTB.Size = new System.Drawing.Size(496, 244);
this.CustomRTB.TabIndex = 10;
this.CustomRTB.Text = "TEST TEST TEST TEST TEST TEST ";
this.CustomRTB.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.СustomRTB_LinkClicked);
this.CustomRTB.SelectionChanged += new System.EventHandler(this.CustomRTB_SelectionChanged);
this.CustomRTB.Click += new System.EventHandler(this.CustomRTB_Click);
this.CustomRTB.TextChanged += new System.EventHandler(this.CustomRTB_TextChanged);
this.CustomRTB.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CustomRTB_KeyDown);
this.CustomRTB.KeyUp += new System.Windows.Forms.KeyEventHandler(this.CustomRTB_KeyUp);
//
// LineNumbers_For_RichTextBox // LineNumbers_For_RichTextBox
// //
this.LineNumbers_For_RichTextBox._SeeThroughMode_ = false; this.LineNumbers_For_RichTextBox._SeeThroughMode_ = false;
@ -911,21 +890,39 @@ public void InitializeComponent()
this.LineNumbers_For_RichTextBox.MarginLines_Thickness = 1F; this.LineNumbers_For_RichTextBox.MarginLines_Thickness = 1F;
this.LineNumbers_For_RichTextBox.Name = "LineNumbers_For_RichTextBox"; this.LineNumbers_For_RichTextBox.Name = "LineNumbers_For_RichTextBox";
this.LineNumbers_For_RichTextBox.Padding = new System.Windows.Forms.Padding(0, 0, 2, 0); this.LineNumbers_For_RichTextBox.Padding = new System.Windows.Forms.Padding(0, 0, 2, 0);
this.LineNumbers_For_RichTextBox.ParentRichTextBox = this.CustomRTB; this.LineNumbers_For_RichTextBox.ParentRichTextBox = this.RichTextBox;
this.LineNumbers_For_RichTextBox.Show_BackgroundGradient = false; this.LineNumbers_For_RichTextBox.Show_BackgroundGradient = false;
this.LineNumbers_For_RichTextBox.Show_BorderLines = true; this.LineNumbers_For_RichTextBox.Show_BorderLines = true;
this.LineNumbers_For_RichTextBox.Show_GridLines = true; this.LineNumbers_For_RichTextBox.Show_GridLines = true;
this.LineNumbers_For_RichTextBox.Show_LineNrs = true; this.LineNumbers_For_RichTextBox.Show_LineNrs = true;
this.LineNumbers_For_RichTextBox.Show_MarginLines = false; this.LineNumbers_For_RichTextBox.Show_MarginLines = false;
this.LineNumbers_For_RichTextBox.Size = new System.Drawing.Size(17, 244); this.LineNumbers_For_RichTextBox.Size = new System.Drawing.Size(18, 244);
this.LineNumbers_For_RichTextBox.TabIndex = 15; this.LineNumbers_For_RichTextBox.TabIndex = 15;
// //
// RichTextBox
//
this.RichTextBox.AcceptsTab = true;
this.RichTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.RichTextBox.ContextMenuStrip = this.EditorMenuStrip;
this.RichTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.RichTextBox.Location = new System.Drawing.Point(18, 47);
this.RichTextBox.Name = "RichTextBox";
this.RichTextBox.Size = new System.Drawing.Size(495, 244);
this.RichTextBox.TabIndex = 16;
this.RichTextBox.Text = "";
this.RichTextBox.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.RichTextBox_LinkClicked);
this.RichTextBox.SelectionChanged += new System.EventHandler(this.RichTextBox_SelectionChanged);
this.RichTextBox.Click += new System.EventHandler(this.RichTextBox_Click);
this.RichTextBox.TextChanged += new System.EventHandler(this.RichTextBox_TextChanged);
this.RichTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.RichTextBox_KeyDown);
this.RichTextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RichTextBox_KeyUp);
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(513, 318); this.ClientSize = new System.Drawing.Size(513, 318);
this.Controls.Add(this.CustomRTB); this.Controls.Add(this.RichTextBox);
this.Controls.Add(this.LineNumbers_For_RichTextBox); this.Controls.Add(this.LineNumbers_For_RichTextBox);
this.Controls.Add(this.SearchPanel); this.Controls.Add(this.SearchPanel);
this.Controls.Add(this.ToolbarPanel); this.Controls.Add(this.ToolbarPanel);
@ -1015,7 +1012,6 @@ public void InitializeComponent()
private System.Windows.Forms.CheckBox WholeWordCheckBox; private System.Windows.Forms.CheckBox WholeWordCheckBox;
private System.Windows.Forms.Panel SearchPanel; private System.Windows.Forms.Panel SearchPanel;
private System.Windows.Forms.ToolStripMenuItem SettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem SettingsToolStripMenuItem;
public CustomRichTextBox CustomRTB;
private System.Windows.Forms.PictureBox CloseSearchPanel; private System.Windows.Forms.PictureBox CloseSearchPanel;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator9; private System.Windows.Forms.ToolStripSeparator toolStripSeparator9;
private System.Windows.Forms.ToolStripMenuItem FindToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem FindToolStripMenuItem;
@ -1041,5 +1037,6 @@ public void InitializeComponent()
private LineNumbers.LineNumbers_For_RichTextBox LineNumbers_For_RichTextBox; private LineNumbers.LineNumbers_For_RichTextBox LineNumbers_For_RichTextBox;
private System.Windows.Forms.ToolStripMenuItem insertToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem insertToolStripMenuItem;
private System.Windows.Forms.Button FindNextButton; private System.Windows.Forms.Button FindNextButton;
private System.Windows.Forms.RichTextBox RichTextBox;
} }
} }

View file

@ -29,8 +29,8 @@ public partial class MainForm : Form
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
CustomRTB.DragDrop += new DragEventHandler(CustomRTB_DragDrop); RichTextBox.DragDrop += new DragEventHandler(RichTextBox_DragDrop);
CustomRTB.AllowDrop = true; RichTextBox.AllowDrop = true;
} }
/*Functions*/ /*Functions*/
@ -62,12 +62,12 @@ private void DecryptAES()
de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
} }
CustomRTB.Text = de; RichTextBox.Text = de;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
filePath = OpenFile.FileName; filePath = OpenFile.FileName;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
PublicVar.openFileName = Path.GetFileName(OpenFile.FileName); PublicVar.openFileName = Path.GetFileName(OpenFile.FileName);
PublicVar.encryptionKey.Set(TypedPassword.Value); PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null; TypedPassword.Value = null;
@ -115,14 +115,14 @@ private void OpenAsotiations()
PublicVar.okPressed = false; PublicVar.okPressed = false;
string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
CustomRTB.Text = de; RichTextBox.Text = de;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
filePath = args[1]; filePath = args[1];
string cc = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
PublicVar.encryptionKey.Set(TypedPassword.Value); PublicVar.encryptionKey.Set(TypedPassword.Value);
CustomRTB.Select(Convert.ToInt32(cc), 0); RichTextBox.Select(Convert.ToInt32(cc), 0);
TypedPassword.Value = null; TypedPassword.Value = null;
} }
catch (CryptographicException) catch (CryptographicException)
@ -140,10 +140,10 @@ private void OpenAsotiations()
{ {
string opnfile = File.ReadAllText(args[1]); string opnfile = File.ReadAllText(args[1]);
string NameWithotPath = Path.GetFileName(args[1]); string NameWithotPath = Path.GetFileName(args[1]);
CustomRTB.Text = opnfile; RichTextBox.Text = opnfile;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
} }
} }
@ -169,13 +169,13 @@ private void SendTo()
} }
PublicVar.okPressed = false; PublicVar.okPressed = false;
string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
CustomRTB.Text = de; RichTextBox.Text = de;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
filePath = argsPath; filePath = argsPath;
string cc = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc), 0); RichTextBox.Select(Convert.ToInt32(cc), 0);
PublicVar.encryptionKey.Set(TypedPassword.Value); PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null; TypedPassword.Value = null;
} }
@ -194,10 +194,10 @@ private void SendTo()
{ {
string opnfile = File.ReadAllText(argsPath); string opnfile = File.ReadAllText(argsPath);
string NameWithotPath = Path.GetFileName(argsPath); string NameWithotPath = Path.GetFileName(argsPath);
CustomRTB.Text = opnfile; RichTextBox.Text = opnfile;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
} }
} }
@ -236,9 +236,9 @@ private void ContextMenuEncryptReplace()
if (!args[1].Contains(".cnp")) if (!args[1].Contains(".cnp"))
{ {
string opnfile = File.ReadAllText(args[1]); string opnfile = File.ReadAllText(args[1]);
CustomRTB.Text = opnfile; RichTextBox.Text = opnfile;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
PublicVar.openFileName = Path.GetFileName(args[1]); PublicVar.openFileName = Path.GetFileName(args[1]);
string newFile = Path.GetDirectoryName(args[1]) + @"\" + Path.GetFileNameWithoutExtension(args[1]) + ".cnp"; string newFile = Path.GetDirectoryName(args[1]) + @"\" + Path.GetFileNameWithoutExtension(args[1]) + ".cnp";
@ -253,17 +253,17 @@ private void ContextMenuEncryptReplace()
File.Delete(args[1]); File.Delete(args[1]);
string noenc = CustomRTB.Text; string noenc = RichTextBox.Text;
string en; string en;
en = AES.Encrypt(CustomRTB.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); en = AES.Encrypt(RichTextBox.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
CustomRTB.Text = en; RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(newFile); StreamWriter sw = new StreamWriter(newFile);
int i = CustomRTB.Lines.Count(); int i = RichTextBox.Lines.Count();
int j = 0; int j = 0;
i = i - 1; i = i - 1;
while (j <= i) while (j <= i)
{ {
sw.WriteLine(CustomRTB.Lines.GetValue(j).ToString()); sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString());
j = j + 1; j = j + 1;
} }
sw.Close(); sw.Close();
@ -272,13 +272,13 @@ private void ContextMenuEncryptReplace()
filePath = newFile; filePath = newFile;
PublicVar.openFileName = Path.GetFileName(newFile); PublicVar.openFileName = Path.GetFileName(newFile);
Text = PublicVar.appName + " " + PublicVar.openFileName; Text = PublicVar.appName + " " + PublicVar.openFileName;
CustomRTB.Text = noenc; RichTextBox.Text = noenc;
} }
#region workaround, strange behavior with the cursor in customRTB fix #region fix strange behavior with the cursor in RichTextBox
CustomRTB.DetectUrls = false; RichTextBox.DetectUrls = false;
CustomRTB.DetectUrls = true; RichTextBox.DetectUrls = true;
CustomRTB.Modified = false; RichTextBox.Modified = false;
#endregion #endregion
if (PublicVar.okPressed) if (PublicVar.okPressed)
@ -293,20 +293,20 @@ private void ContextMenuEncrypt()
{ {
string opnfile = File.ReadAllText(args[1]); string opnfile = File.ReadAllText(args[1]);
string NameWithotPath = Path.GetFileName(args[1]); string NameWithotPath = Path.GetFileName(args[1]);
CustomRTB.Text = opnfile; RichTextBox.Text = opnfile;
Text = PublicVar.appName + NameWithotPath; Text = PublicVar.appName + NameWithotPath;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
PublicVar.openFileName = Path.GetFileName(args[1]); PublicVar.openFileName = Path.GetFileName(args[1]);
filePath = OpenFile.FileName; filePath = OpenFile.FileName;
} }
#region workaround, strange behavior with the cursor in customRTB fix #region fix strange behavior with the cursor in RichTextBox
CustomRTB.DetectUrls = false; RichTextBox.DetectUrls = false;
CustomRTB.DetectUrls = true; RichTextBox.DetectUrls = true;
#endregion #endregion
CustomRTB.Modified = false; RichTextBox.Modified = false;
if (PublicVar.okPressed) if (PublicVar.okPressed)
{ {
@ -339,7 +339,7 @@ private void DeleteUpdateFiles()
private void SaveConfirm(bool exit) private void SaveConfirm(bool exit)
{ {
if (!CustomRTB.Modified) if (!RichTextBox.Modified)
{ {
if (exit) if (exit)
{ {
@ -353,7 +353,7 @@ private void SaveConfirm(bool exit)
PublicVar.openFileName = "Unnamed.cnp"; PublicVar.openFileName = "Unnamed.cnp";
} }
if (CustomRTB.Text != "") if (RichTextBox.Text != "")
{ {
string messageBoxText = ""; string messageBoxText = "";
@ -455,7 +455,7 @@ private void AutoLock(bool minimize)
{ {
EnterKeyForm f2 = new EnterKeyForm(); EnterKeyForm f2 = new EnterKeyForm();
PublicVar.encryptionKey.Set(null); PublicVar.encryptionKey.Set(null);
caretPos = CustomRTB.SelectionStart; caretPos = RichTextBox.SelectionStart;
f2.MinimizeBox = true; f2.MinimizeBox = true;
Hide(); Hide();
@ -468,7 +468,7 @@ private void AutoLock(bool minimize)
if (!PublicVar.okPressed) if (!PublicVar.okPressed)
{ {
PublicVar.encryptionKey.Set(null); PublicVar.encryptionKey.Set(null);
CustomRTB.Clear(); RichTextBox.Clear();
Text = PublicVar.appName; Text = PublicVar.appName;
PublicVar.openFileName = null; PublicVar.openFileName = null;
filePath = ""; filePath = "";
@ -479,14 +479,14 @@ private void AutoLock(bool minimize)
LineNumbers_For_RichTextBox.Refresh(); LineNumbers_For_RichTextBox.Refresh();
try try
{ {
CustomRTB.Clear(); RichTextBox.Clear();
string opnfile = File.ReadAllText(filePath); string opnfile = File.ReadAllText(filePath);
string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
CustomRTB.Text = de; RichTextBox.Text = de;
Text = PublicVar.appName + " " + PublicVar.openFileName; Text = PublicVar.appName + " " + PublicVar.openFileName;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
CustomRTB.SelectionStart = caretPos; RichTextBox.SelectionStart = caretPos;
PublicVar.encryptionKey.Set(TypedPassword.Value); PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null; TypedPassword.Value = null;
Show(); Show();
@ -504,7 +504,7 @@ private void AutoLock(bool minimize)
if (dialogResult == DialogResult.Cancel) if (dialogResult == DialogResult.Cancel)
{ {
PublicVar.encryptionKey.Set(null); PublicVar.encryptionKey.Set(null);
CustomRTB.Clear(); RichTextBox.Clear();
Text = PublicVar.appName; Text = PublicVar.appName;
filePath = ""; filePath = "";
PublicVar.openFileName = null; PublicVar.openFileName = null;
@ -590,9 +590,9 @@ private void MainWindow_Activated(object sender, EventArgs e)
if (PublicVar.settingsChanged) if (PublicVar.settingsChanged)
{ {
PublicVar.settingsChanged = false; PublicVar.settingsChanged = false;
CustomRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize); RichTextBox.Font = new Font(ps.RichTextFont, ps.RichTextSize);
CustomRTB.ForeColor = ps.RichForeColor; RichTextBox.ForeColor = ps.RichForeColor;
CustomRTB.BackColor = ps.RichBackColor; RichTextBox.BackColor = ps.RichBackColor;
BackColor = ps.RichBackColor; BackColor = ps.RichBackColor;
LineNumbers_For_RichTextBox.Visible = bool.Parse(ps.LNVisible); LineNumbers_For_RichTextBox.Visible = bool.Parse(ps.LNVisible);
@ -631,8 +631,8 @@ private void MainWindow_Activated(object sender, EventArgs e)
} }
#region workaround, unhighlight URLs fix #region workaround, unhighlight URLs fix
CustomRTB.DetectUrls = false; RichTextBox.DetectUrls = false;
CustomRTB.DetectUrls = true; RichTextBox.DetectUrls = true;
#endregion #endregion
if (!ps.ShowToolbar && ToolbarPanel.Visible) if (!ps.ShowToolbar && ToolbarPanel.Visible)
@ -660,7 +660,7 @@ private void MainWindow_Activated(object sender, EventArgs e)
if (PublicVar.keyChanged) if (PublicVar.keyChanged)
{ {
CustomRTB.Modified = true; RichTextBox.Modified = true;
} }
if (PublicVar.encryptionKey.Get() == null) if (PublicVar.encryptionKey.Get() == null)
@ -697,7 +697,7 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
ps.Save(); ps.Save();
SaveConfirm(true); SaveConfirm(true);
if (CustomRTB.Text == "") if (RichTextBox.Text == "")
{ {
noExit = false; noExit = false;
} }
@ -712,12 +712,12 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
private void MainWindow_Load(object sender, EventArgs e) private void MainWindow_Load(object sender, EventArgs e)
{ {
string pos = ps.WindowLocation.ToString(); string pos = ps.WindowLocation.ToString();
CustomRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize); RichTextBox.Font = new Font(ps.RichTextFont, ps.RichTextSize);
CustomRTB.ForeColor = ps.RichForeColor; RichTextBox.ForeColor = ps.RichForeColor;
CustomRTB.BackColor = ps.RichBackColor; RichTextBox.BackColor = ps.RichBackColor;
BackColor = ps.RichBackColor; BackColor = ps.RichBackColor;
WordWrapToolStripMenuItem.Checked = ps.MenuWrap; WordWrapToolStripMenuItem.Checked = ps.MenuWrap;
CustomRTB.WordWrap = ps.RichWrap; RichTextBox.WordWrap = ps.RichWrap;
ToolbarPanel.Visible = ps.ShowToolbar; ToolbarPanel.Visible = ps.ShowToolbar;
LineNumbers_For_RichTextBox.Visible = bool.Parse(ps.LNVisible); LineNumbers_For_RichTextBox.Visible = bool.Parse(ps.LNVisible);
LineNumbers_For_RichTextBox.ForeColor = ps.LNFontColorPanel; LineNumbers_For_RichTextBox.ForeColor = ps.LNFontColorPanel;
@ -810,10 +810,10 @@ private void MainWindow_Load(object sender, EventArgs e)
/*Form Events*/ /*Form Events*/
/*CustomRTB Events*/ /*RichTextBox Events*/
private void CustomRTB_SelectionChanged(object sender, EventArgs e) private void RichTextBox_SelectionChanged(object sender, EventArgs e)
{ {
if (CustomRTB.SelectionLength != 0) if (RichTextBox.SelectionLength != 0)
{ {
CutToolbarButton.Enabled = true; CutToolbarButton.Enabled = true;
CopyToolbarButton.Enabled = true; CopyToolbarButton.Enabled = true;
@ -825,14 +825,14 @@ private void CustomRTB_SelectionChanged(object sender, EventArgs e)
} }
} }
private void CustomRTB_Click(object sender, EventArgs e) private void RichTextBox_Click(object sender, EventArgs e)
{ {
caretPos = CustomRTB.SelectionStart; caretPos = RichTextBox.SelectionStart;
} }
private void CustomRTB_KeyDown(object sender, KeyEventArgs e) private void RichTextBox_KeyDown(object sender, KeyEventArgs e)
{ {
caretPos = CustomRTB.SelectionStart; caretPos = RichTextBox.SelectionStart;
if (e.KeyCode == Keys.ShiftKey) if (e.KeyCode == Keys.ShiftKey)
{ {
shiftPresed = true; shiftPresed = true;
@ -842,14 +842,14 @@ private void CustomRTB_KeyDown(object sender, KeyEventArgs e)
{ {
SearchTextBox.Text = ""; SearchTextBox.Text = "";
SearchPanel.Visible = false; SearchPanel.Visible = false;
CustomRTB.Focus(); RichTextBox.Focus();
CustomRTB.DeselectAll(); RichTextBox.DeselectAll();
e.Handled = e.SuppressKeyPress = true; e.Handled = e.SuppressKeyPress = true;
findPos = 0; findPos = 0;
} }
} }
private void СustomRTB_LinkClicked(object sender, LinkClickedEventArgs e) private void RichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
{ {
if (shiftPresed) if (shiftPresed)
{ {
@ -858,7 +858,7 @@ private void CustomRTB_KeyDown(object sender, KeyEventArgs e)
} }
} }
private void CustomRTB_DragDrop(object sender, DragEventArgs e) private void RichTextBox_DragDrop(object sender, DragEventArgs e)
{ {
SaveConfirm(false); SaveConfirm(false);
@ -875,10 +875,10 @@ private void CustomRTB_DragDrop(object sender, DragEventArgs e)
{ {
string opnfile = File.ReadAllText(OpenFile.FileName); string opnfile = File.ReadAllText(OpenFile.FileName);
string NameWithotPath = Path.GetFileName(OpenFile.FileName); string NameWithotPath = Path.GetFileName(OpenFile.FileName);
CustomRTB.Text = opnfile; RichTextBox.Text = opnfile;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
filePath = OpenFile.FileName; filePath = OpenFile.FileName;
return; return;
} }
@ -905,18 +905,18 @@ private void CustomRTB_DragDrop(object sender, DragEventArgs e)
} }
} }
private void CustomRTB_KeyUp(object sender, KeyEventArgs e) private void RichTextBox_KeyUp(object sender, KeyEventArgs e)
{ {
if (e.KeyCode == Keys.ShiftKey) if (e.KeyCode == Keys.ShiftKey)
{ {
shiftPresed = false; shiftPresed = false;
} }
} }
private void CustomRTB_TextChanged(object sender, EventArgs e) private void RichTextBox_TextChanged(object sender, EventArgs e)
{ {
LineNumbers_For_RichTextBox.Refresh(); LineNumbers_For_RichTextBox.Refresh();
} }
/*CustomRTB Events*/ /*RichTextBox Events*/
/* Main Menu */ /* Main Menu */
@ -950,7 +950,7 @@ private void NewToolStripMenuItem_Click(object sender, EventArgs e)
return; return;
} }
CustomRTB.Clear(); RichTextBox.Clear();
StreamWriter sw = new StreamWriter(SaveFile.FileName); StreamWriter sw = new StreamWriter(SaveFile.FileName);
string NameWithotPath = Path.GetFileName(SaveFile.FileName); string NameWithotPath = Path.GetFileName(SaveFile.FileName);
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
@ -973,20 +973,20 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{ {
string opnfile = File.ReadAllText(OpenFile.FileName); string opnfile = File.ReadAllText(OpenFile.FileName);
string NameWithotPath = Path.GetFileName(OpenFile.FileName); string NameWithotPath = Path.GetFileName(OpenFile.FileName);
CustomRTB.Text = opnfile; RichTextBox.Text = opnfile;
Text = PublicVar.appName + " " + NameWithotPath; Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
CustomRTB.Select(Convert.ToInt32(cc2), 0); RichTextBox.Select(Convert.ToInt32(cc2), 0);
return; return;
} }
DecryptAES(); DecryptAES();
#region workaround, strange behavior with the cursor in customRTB fix #region fix strange behavior with the cursor in RichTextBox
CustomRTB.DetectUrls = false; RichTextBox.DetectUrls = false;
CustomRTB.DetectUrls = true; RichTextBox.DetectUrls = true;
#endregion #endregion
CustomRTB.Modified = false; RichTextBox.Modified = false;
if (PublicVar.okPressed) if (PublicVar.okPressed)
{ {
@ -1013,7 +1013,7 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{ {
int saveCaret = CustomRTB.SelectionStart; int saveCaret = RichTextBox.SelectionStart;
if (PublicVar.encryptionKey.Get() == null) if (PublicVar.encryptionKey.Get() == null)
{ {
@ -1025,32 +1025,32 @@ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
PublicVar.okPressed = false; PublicVar.okPressed = false;
} }
string noenc = CustomRTB.Text; string noenc = RichTextBox.Text;
string en; string en;
en = AES.Encrypt(CustomRTB.Text, PublicVar.encryptionKey.Get(), null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); en = AES.Encrypt(RichTextBox.Text, PublicVar.encryptionKey.Get(), null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
CustomRTB.Text = en; RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(filePath); StreamWriter sw = new StreamWriter(filePath);
int i = CustomRTB.Lines.Count(); int i = RichTextBox.Lines.Count();
int j = 0; int j = 0;
i = i - 1; i = i - 1;
while (j <= i) while (j <= i)
{ {
sw.WriteLine(CustomRTB.Lines.GetValue(j).ToString()); sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString());
j = j + 1; j = j + 1;
} }
sw.Close(); sw.Close();
CustomRTB.Text = noenc; RichTextBox.Text = noenc;
CustomRTB.Select(Convert.ToInt32(saveCaret), 0); RichTextBox.Select(Convert.ToInt32(saveCaret), 0);
PublicVar.keyChanged = false; PublicVar.keyChanged = false;
} }
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
int saveCaret = CustomRTB.SelectionStart; int saveCaret = RichTextBox.SelectionStart;
string NameWithotPath = Path.GetFileName(OpenFile.FileName); string NameWithotPath = Path.GetFileName(OpenFile.FileName);
if (filePath != "") if (filePath != "")
{ {
@ -1085,23 +1085,23 @@ private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
} }
filePath = SaveFile.FileName; filePath = SaveFile.FileName;
string noenc = CustomRTB.Text; string noenc = RichTextBox.Text;
string en; string en;
en = AES.Encrypt(CustomRTB.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); en = AES.Encrypt(RichTextBox.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
CustomRTB.Text = en; RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(filePath); StreamWriter sw = new StreamWriter(filePath);
int i = CustomRTB.Lines.Count(); int i = RichTextBox.Lines.Count();
int j = 0; int j = 0;
i = i - 1; i = i - 1;
while (j <= i) while (j <= i)
{ {
sw.WriteLine(CustomRTB.Lines.GetValue(j).ToString()); sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString());
j = j + 1; j = j + 1;
} }
sw.Close(); sw.Close();
CustomRTB.Text = noenc; RichTextBox.Text = noenc;
Text = PublicVar.appName + " " + Path.GetFileName(filePath); Text = PublicVar.appName + " " + Path.GetFileName(filePath);
CustomRTB.Select(Convert.ToInt32(saveCaret), 0); RichTextBox.Select(Convert.ToInt32(saveCaret), 0);
PublicVar.encryptionKey.Set(TypedPassword.Value); PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null; TypedPassword.Value = null;
PublicVar.openFileName = Path.GetFileName(SaveFile.FileName); PublicVar.openFileName = Path.GetFileName(SaveFile.FileName);
@ -1121,7 +1121,7 @@ private void DeleteFileToolStripMenuItem_Click(object sender, EventArgs e)
if (MessageBox.Show("Delete file: " + "\"" + filePath + "\"" + " ?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) if (MessageBox.Show("Delete file: " + "\"" + filePath + "\"" + " ?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
File.Delete(filePath); File.Delete(filePath);
CustomRTB.Clear(); RichTextBox.Clear();
PublicVar.encryptionKey.Set(null); PublicVar.encryptionKey.Set(null);
FileLocationToolbarButton.Enabled = false; FileLocationToolbarButton.Enabled = false;
DeleteFileToolbarButton.Enabled = false; DeleteFileToolbarButton.Enabled = false;
@ -1159,29 +1159,29 @@ private void FileToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
/*Edit*/ /*Edit*/
private void UndoToolStripMenuItem_Click(object sender, EventArgs e) private void UndoToolStripMenuItem_Click(object sender, EventArgs e)
{ {
CustomRTB.Undo(); RichTextBox.Undo();
} }
public void RedoToolStripMenuItem_Click(object sender, EventArgs e) public void RedoToolStripMenuItem_Click(object sender, EventArgs e)
{ {
CustomRTB.Redo(); RichTextBox.Redo();
} }
private void CutToolStripMenuItem_Click(object sender, EventArgs e) private void CutToolStripMenuItem_Click(object sender, EventArgs e)
{ {
CustomRTB.Cut(); RichTextBox.Cut();
} }
private void CopyToolStripMenuItem_Click(object sender, EventArgs e) private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{ {
CustomRTB.Copy(); RichTextBox.Copy();
} }
private void PasteToolStripMenuItem_Click(object sender, EventArgs e) private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (CustomRTB.Focused) if (RichTextBox.Focused)
{ {
CustomRTB.Paste(DataFormats.GetFormat(DataFormats.Text)); RichTextBox.Paste(DataFormats.GetFormat(DataFormats.Text));
} }
if (SearchTextBox.Focused) if (SearchTextBox.Focused)
{ {
@ -1191,7 +1191,7 @@ private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e) private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
{ {
CustomRTB.SelectedText = ""; RichTextBox.SelectedText = "";
} }
private void FindToolStripMenuItem_Click(object sender, EventArgs e) private void FindToolStripMenuItem_Click(object sender, EventArgs e)
@ -1200,9 +1200,8 @@ private void FindToolStripMenuItem_Click(object sender, EventArgs e)
{ {
SearchTextBox.Text = ""; SearchTextBox.Text = "";
SearchPanel.Visible = false; SearchPanel.Visible = false;
CustomRTB.Focus(); RichTextBox.Focus();
CustomRTB.DeselectAll(); RichTextBox.DeselectAll();
//CustomRTB.SelectionStart = caretPos;
} }
else else
{ {
@ -1213,9 +1212,9 @@ private void FindToolStripMenuItem_Click(object sender, EventArgs e)
private void SelectAllToolStripMenuItem_Click(object sender, EventArgs e) private void SelectAllToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (CustomRTB.Focused) if (RichTextBox.Focused)
{ {
CustomRTB.SelectAll(); RichTextBox.SelectAll();
} }
if (SearchTextBox.Focused) if (SearchTextBox.Focused)
{ {
@ -1227,25 +1226,25 @@ private void WordWrapToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (WordWrapToolStripMenuItem.Checked) if (WordWrapToolStripMenuItem.Checked)
{ {
CustomRTB.WordWrap = true; RichTextBox.WordWrap = true;
} }
else else
{ {
CustomRTB.WordWrap = false; RichTextBox.WordWrap = false;
} }
ps.MenuWrap = WordWrapToolStripMenuItem.Checked; ps.MenuWrap = WordWrapToolStripMenuItem.Checked;
ps.RichWrap = CustomRTB.WordWrap; ps.RichWrap = RichTextBox.WordWrap;
ps.Save(); ps.Save();
} }
private void ClearToolStripMenuItem_Click(object sender, EventArgs e) private void ClearToolStripMenuItem_Click(object sender, EventArgs e)
{ {
CustomRTB.Clear(); RichTextBox.Clear();
} }
private void EditToolStripMenuItem_DropDownOpened(object sender, EventArgs e) private void EditToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{ {
if (CustomRTB.SelectionLength != 0) if (RichTextBox.SelectionLength != 0)
{ {
CutToolStripMenuItem.Enabled = true; CutToolStripMenuItem.Enabled = true;
CopyToolStripMenuItem.Enabled = true; CopyToolStripMenuItem.Enabled = true;
@ -1365,20 +1364,20 @@ private void RightToLeftEditorMenuStrip_Click(object sender, EventArgs e)
{ {
if (!WordWrapToolStripMenuItem.Checked) if (!WordWrapToolStripMenuItem.Checked)
{ {
string rtbTxt = CustomRTB.Text; string rtbTxt = RichTextBox.Text;
CustomRTB.Clear(); RichTextBox.Clear();
CustomRTB.RightToLeft = RightToLeft.Yes; RichTextBox.RightToLeft = RightToLeft.Yes;
Application.DoEvents(); Application.DoEvents();
CustomRTB.Text = rtbTxt; RichTextBox.Text = rtbTxt;
} }
else else
{ {
CustomRTB.RightToLeft = RightToLeft.Yes; RichTextBox.RightToLeft = RightToLeft.Yes;
} }
} }
else else
{ {
CustomRTB.RightToLeft = RightToLeft.No; RichTextBox.RightToLeft = RightToLeft.No;
} }
} }
@ -1389,7 +1388,7 @@ private void ClearEditorMenuStrip_Click(object sender, EventArgs e)
private void EditorMenuStrip_Opening(object sender, CancelEventArgs e) private void EditorMenuStrip_Opening(object sender, CancelEventArgs e)
{ {
if (CustomRTB.SelectionLength != 0) if (RichTextBox.SelectionLength != 0)
{ {
CutEditorMenuStrip.Enabled = true; CutEditorMenuStrip.Enabled = true;
CopyEditorMenuStrip.Enabled = true; CopyEditorMenuStrip.Enabled = true;
@ -1481,7 +1480,6 @@ private void CloseToolbar_MouseLeave(object sender, EventArgs e)
/*Search Panel*/ /*Search Panel*/
private void SearchTextBox_TextChanged(object sender, EventArgs e) private void SearchTextBox_TextChanged(object sender, EventArgs e)
{ {
findPos = 0; findPos = 0;
@ -1493,8 +1491,8 @@ private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
{ {
SearchTextBox.Text = ""; SearchTextBox.Text = "";
SearchPanel.Visible = false; SearchPanel.Visible = false;
CustomRTB.Focus(); RichTextBox.Focus();
CustomRTB.DeselectAll(); RichTextBox.DeselectAll();
e.Handled = e.SuppressKeyPress = true; e.Handled = e.SuppressKeyPress = true;
findPos = 0; findPos = 0;
} }
@ -1518,13 +1516,13 @@ private void CloseSearchPanel_MouseLeave(object sender, EventArgs e)
private void MatchCaseCheckBox_CheckedChanged(object sender, EventArgs e) private void MatchCaseCheckBox_CheckedChanged(object sender, EventArgs e)
{ {
findPos = 0; findPos = 0;
CustomRTB.DeselectAll(); RichTextBox.DeselectAll();
} }
private void WholeWordCheckBox_CheckedChanged(object sender, EventArgs e) private void WholeWordCheckBox_CheckedChanged(object sender, EventArgs e)
{ {
findPos = 0; findPos = 0;
CustomRTB.DeselectAll(); RichTextBox.DeselectAll();
} }
private void FindMyText(string text, RichTextBoxFinds findOptions) private void FindMyText(string text, RichTextBoxFinds findOptions)
@ -1533,14 +1531,14 @@ private void FindMyText(string text, RichTextBoxFinds findOptions)
{ {
try try
{ {
findPos = CustomRTB.Find(SearchTextBox.Text, findPos, findOptions); findPos = RichTextBox.Find(SearchTextBox.Text, findPos, findOptions);
if (findPos == -1) if (findPos == -1)
{ {
findPos = 0; findPos = 0;
return; return;
} }
CustomRTB.Focus(); RichTextBox.Focus();
CustomRTB.Select(findPos, SearchTextBox.Text.Length); RichTextBox.Select(findPos, SearchTextBox.Text.Length);
findPos += SearchTextBox.Text.Length + 1; findPos += SearchTextBox.Text.Length + 1;
} }
catch catch
@ -1592,7 +1590,7 @@ private void MainVariablesToolStripMenuItem_Click(object sender, EventArgs e)
Debug.WriteLine("keyChanged: " + PublicVar.keyChanged); Debug.WriteLine("keyChanged: " + PublicVar.keyChanged);
Debug.WriteLine("settingsChanged: " + PublicVar.settingsChanged); Debug.WriteLine("settingsChanged: " + PublicVar.settingsChanged);
Debug.WriteLine("okPressed: " + PublicVar.okPressed); Debug.WriteLine("okPressed: " + PublicVar.okPressed);
Debug.WriteLine("CustomRTB.Modified: " + CustomRTB.Modified); Debug.WriteLine("RichTextBox.Modified: " + RichTextBox.Modified);
Debug.WriteLine("EditorMenuStrip: " + EditorMenuStrip.Enabled); Debug.WriteLine("EditorMenuStrip: " + EditorMenuStrip.Enabled);
#endif #endif
} }