Custom "RichTextBox" replaced to common "RichTextBox"

This commit is contained in:
Alexander 2019-08-22 22:30:34 +03:00
parent d9271d947b
commit 8fb1438b36
7 changed files with 53 additions and 239 deletions

View file

@ -36,8 +36,8 @@ private void InitializeComponent()
this.LicenseLinkLabel = new System.Windows.Forms.LinkLabel();
this.GithubLinkLabel = new System.Windows.Forms.LinkLabel();
this.ContributorsLabel = new System.Windows.Forms.Label();
this.ContributorsRichTextBox = new Crypto_Notepad.CustomRichTextBox();
this.TPDRichTextBox = new Crypto_Notepad.CustomRichTextBox();
this.TPDRichTextBox = new System.Windows.Forms.RichTextBox();
this.ContributorsRichTextBox = new System.Windows.Forms.RichTextBox();
((System.ComponentModel.ISupportInitialize)(this.AppLogoPictureBox)).BeginInit();
this.SuspendLayout();
//
@ -142,29 +142,11 @@ private void InitializeComponent()
this.ContributorsLabel.TabIndex = 4;
this.ContributorsLabel.Text = "Contributors:";
//
// ContributorsRichTextBox
//
this.ContributorsRichTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(50)))));
this.ContributorsRichTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ContributorsRichTextBox.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.ContributorsRichTextBox.ForeColor = System.Drawing.Color.White;
this.ContributorsRichTextBox.Location = new System.Drawing.Point(-1, 128);
this.ContributorsRichTextBox.Name = "ContributorsRichTextBox";
this.ContributorsRichTextBox.ReadOnly = true;
this.ContributorsRichTextBox.RightMargin = 600;
this.ContributorsRichTextBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.ContributorsRichTextBox.ShowSelectionMargin = true;
this.ContributorsRichTextBox.Size = new System.Drawing.Size(398, 19);
this.ContributorsRichTextBox.TabIndex = 8;
this.ContributorsRichTextBox.TabStop = false;
this.ContributorsRichTextBox.Text = "h5p9sl https://github.com/h5p9sl";
this.ContributorsRichTextBox.WordWrap = false;
this.ContributorsRichTextBox.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.TPDRichTextBox_LinkClicked);
//
// TPDRichTextBox
//
this.TPDRichTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(50)))));
this.TPDRichTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.TPDRichTextBox.Dock = System.Windows.Forms.DockStyle.Bottom;
this.TPDRichTextBox.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.TPDRichTextBox.ForeColor = System.Drawing.Color.White;
this.TPDRichTextBox.Location = new System.Drawing.Point(0, 181);
@ -173,24 +155,41 @@ private void InitializeComponent()
this.TPDRichTextBox.RightMargin = 700;
this.TPDRichTextBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Horizontal;
this.TPDRichTextBox.ShowSelectionMargin = true;
this.TPDRichTextBox.Size = new System.Drawing.Size(400, 121);
this.TPDRichTextBox.TabIndex = 8;
this.TPDRichTextBox.TabStop = false;
this.TPDRichTextBox.Size = new System.Drawing.Size(397, 103);
this.TPDRichTextBox.TabIndex = 10;
this.TPDRichTextBox.Text = resources.GetString("TPDRichTextBox.Text");
this.TPDRichTextBox.WordWrap = false;
this.TPDRichTextBox.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.TPDRichTextBox_LinkClicked);
//
// ContributorsRichTextBox
//
this.ContributorsRichTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(50)))));
this.ContributorsRichTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ContributorsRichTextBox.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.ContributorsRichTextBox.ForeColor = System.Drawing.Color.White;
this.ContributorsRichTextBox.Location = new System.Drawing.Point(0, 125);
this.ContributorsRichTextBox.Name = "ContributorsRichTextBox";
this.ContributorsRichTextBox.ReadOnly = true;
this.ContributorsRichTextBox.RightMargin = 700;
this.ContributorsRichTextBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.ContributorsRichTextBox.ShowSelectionMargin = true;
this.ContributorsRichTextBox.Size = new System.Drawing.Size(397, 18);
this.ContributorsRichTextBox.TabIndex = 11;
this.ContributorsRichTextBox.Text = "h5p9sl https://github.com/h5p9sl";
this.ContributorsRichTextBox.WordWrap = false;
this.ContributorsRichTextBox.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.ContributorsRichTextBox_LinkClicked);
//
// AboutFrom
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(45)))), ((int)(((byte)(50)))));
this.ClientSize = new System.Drawing.Size(397, 302);
this.ClientSize = new System.Drawing.Size(397, 284);
this.Controls.Add(this.ContributorsRichTextBox);
this.Controls.Add(this.TPDRichTextBox);
this.Controls.Add(this.GithubLinkLabel);
this.Controls.Add(this.LicenseLinkLabel);
this.Controls.Add(this.AuthorLinkLabel);
this.Controls.Add(this.ContributorsRichTextBox);
this.Controls.Add(this.TPDRichTextBox);
this.Controls.Add(this.AppLogoPictureBox);
this.Controls.Add(this.AppVersionLabel);
this.Controls.Add(this.ContributorsLabel);
@ -215,11 +214,11 @@ private void InitializeComponent()
private System.Windows.Forms.Label AppVersionLabel;
private System.Windows.Forms.PictureBox AppLogoPictureBox;
private System.Windows.Forms.Label TPDLabel;
private CustomRichTextBox TPDRichTextBox;
private System.Windows.Forms.LinkLabel AuthorLinkLabel;
private System.Windows.Forms.LinkLabel LicenseLinkLabel;
private System.Windows.Forms.LinkLabel GithubLinkLabel;
private System.Windows.Forms.Label ContributorsLabel;
private CustomRichTextBox ContributorsRichTextBox;
private System.Windows.Forms.RichTextBox TPDRichTextBox;
private System.Windows.Forms.RichTextBox ContributorsRichTextBox;
}
}

View file

@ -68,6 +68,11 @@ private void TPDRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
{
Process.Start(e.LinkText);
}
private void ContributorsRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
{
Process.Start(e.LinkText);
}
/*Perform open links*/
}

View file

@ -371,11 +371,9 @@
<value>Line Numbers for RichTextBox: https://www.codeproject.com/Articles/38858/Line-Numbers-for-RichText-Control-in-C
CustomSettingsProvider: http://www.codeproject.com/Articles/20917/Settings-Provider
MsgBoxCenterParent: http://stackoverflow.com/a/2576220/4430027
CustomRichTextBox: https://code.msdn.microsoft.com/windowsdesktop/How-to-find-the-text-and-e92b8d78
DotNetZip: https://www.nuget.org/packages/DotNetZip/
Icons: http://p.yusukekamiyamane.com/
AES: http://www.codeproject.com/Answers/391219/AES#answer2
</value>
AES: http://www.codeproject.com/Answers/391219/AES#answer2</value>
</data>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>44</value>

View file

@ -103,12 +103,6 @@
<Compile Include="ChangeKeyForm.Designer.cs">
<DependentUpon>ChangeKeyForm.cs</DependentUpon>
</Compile>
<Compile Include="CustomRichTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CustomRichTextBox.Designer.cs">
<DependentUpon>CustomRichTextBox.cs</DependentUpon>
</Compile>
<Compile Include="EncryptedString.cs" />
<Compile Include="linenum_rtf.cs">
<SubType>Component</SubType>

View file

@ -1,36 +0,0 @@
namespace Crypto_Notepad
{
partial class CustomRichTextBox
{
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View file

@ -1,146 +0,0 @@
/****************************** Module Header ******************************\
* Module Name: CustomRichTextBox.cs
* Project: CSWinFormSearchAndHighlightText
* Copyright(c) Microsoft Corporation.
*
* Theclass is used to create custom RichTextBox
* The custom RichTextBox add custom Highlight and ClearHighlight method
*
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/en-us/openness/licenses.aspx.
* All other rights reserved.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;
namespace Crypto_Notepad
{
/// <summary>
/// Custom RichTextBox control
/// </summary>
public partial class CustomRichTextBox : RichTextBox
{
public CustomRichTextBox()
: base()
{
InitializeComponent();
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
//this message is sent to the control when we scroll using the mouse
private const int WM_MOUSEWHEEL = 0x20A;
//and this one issues the control to perform scrolling
private const int WM_VSCROLL = 0x115;
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (!base.AutoWordSelection)
{
base.AutoWordSelection = true;
base.AutoWordSelection = false;
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_MOUSEWHEEL)
{
int scrollLines = SystemInformation.MouseWheelScrollLines;
for (int i = 0; i < scrollLines; i++)
{
try
{
if ((int)m.WParam >= 0) // when wParam is greater than 0
SendMessage(this.Handle, WM_VSCROLL, (IntPtr)0, IntPtr.Zero); // scroll up
else
SendMessage(this.Handle, WM_VSCROLL, (IntPtr)1, IntPtr.Zero); // scroll down
}
catch (OverflowException)
{
SendMessage(this.Handle, WM_VSCROLL, (IntPtr)1, IntPtr.Zero); // scroll down
}
}
return;
}
base.WndProc(ref m);
}
/// <summary>
/// Search and Highlight all text in RichTextBox Control
/// </summary>
/// <param name="findWhat">Find What</param>
/// <param name="highlightColor">Highlight Color</param>
/// <param name="ismatchCase">Is Match Case</param>
/// <param name="ismatchWholeWord">Is Match Whole Word</param>
/// <returns></returns>
public bool Highlight(string findWhat, Color highlightColor, bool ismatchCase, bool ismatchWholeWord)
{
// Clear all highlights before searching text again
ClearHighlight();
int startSearch = 0;
//int searchLength = findWhat.Length;
RichTextBoxFinds findoptions = default(RichTextBoxFinds);
// Setup the search options.
if (ismatchCase && ismatchWholeWord)
{
findoptions = RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord;
}
else if (ismatchCase)
{
findoptions = RichTextBoxFinds.MatchCase;
}
else if (ismatchWholeWord)
{
findoptions = RichTextBoxFinds.WholeWord;
}
else
{
findoptions = RichTextBoxFinds.None;
}
// detect whether search text exists in richtextbox
bool isfind = false;
int index = -1;
// Search text in RichTextBox and highlight them with color.
int max = this.TextLength;
while (startSearch < max && (index = this.Find(findWhat, startSearch, findoptions)) > -1)
{
isfind = true;
this.SelectionBackColor = highlightColor;
// Continue after the one we searched
startSearch = index + 1;
}
// If the text exist in RichTextBox control, then return true, otherwise, return false
return isfind;
}
/// <summary>
/// Clear all Highlights
/// </summary>
private void ClearHighlight()
{
Properties.Settings ps = Properties.Settings.Default;
this.SelectAll();
this.SelectionBackColor = ps.RichBackColor;
}
}
}

View file

@ -102,8 +102,8 @@ public void InitializeComponent()
this.FileLocationToolbarButton = new System.Windows.Forms.PictureBox();
this.SaveToolBarButton = new System.Windows.Forms.PictureBox();
this.OpenToolbarButton = new System.Windows.Forms.PictureBox();
this.LineNumbers_For_RichTextBox = new LineNumbers.LineNumbers_For_RichTextBox();
this.RichTextBox = new System.Windows.Forms.RichTextBox();
this.LineNumbers_For_RichTextBox = new LineNumbers.LineNumbers_For_RichTextBox();
this.MainMenu.SuspendLayout();
this.EditorMenuStrip.SuspendLayout();
this.SearchPanel.SuspendLayout();
@ -858,6 +858,24 @@ public void InitializeComponent()
this.OpenToolbarButton.TabStop = false;
this.OpenToolbarButton.Click += new System.EventHandler(this.OpenToolbarButton_Click);
//
// 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);
//
// LineNumbers_For_RichTextBox
//
this.LineNumbers_For_RichTextBox._SeeThroughMode_ = false;
@ -899,24 +917,6 @@ public void InitializeComponent()
this.LineNumbers_For_RichTextBox.Size = new System.Drawing.Size(18, 244);
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);