NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;

namespace CSharp_Kod_Hatırlatıcı
{
public class SyntaxRichTextBox : System.Windows.Forms.RichTextBox
{
private readonly SyntaxSettings _mSettings = new SyntaxSettings();
private static bool _mBPaint = true;
private string _mStrLine = "";
private int _mNLineLength;
private int _mnLineStart;
private int _mNLineEnd;
private string _mStrKeywords = "";

/// <summary>
/// The settings.
/// </summary>
public SyntaxSettings Settings
{
get { return _mSettings; }
}

/// <summary>
/// WndProc
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == 0x00f)
{
if (_mBPaint)
base.WndProc(ref m);
else
m.Result = IntPtr.Zero;
}

else
base.WndProc(ref m);
}
/// <summary>
/// OnTextChanged
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(EventArgs e)
{
// Calculate shit here.

int nCurrentSelectionStart = SelectionStart;

_mBPaint = false;

// Find the start of the current line.
_mnLineStart = nCurrentSelectionStart;
while ((_mnLineStart > 0) && (Text[_mnLineStart - 1] != 'n'))
_mnLineStart--;
// Find the end of the current line.
_mNLineEnd = nCurrentSelectionStart;
while ((_mNLineEnd < Text.Length) && (Text[_mNLineEnd] != 'n'))
_mNLineEnd++;
// Calculate the length of the line.
_mNLineLength = _mNLineEnd - _mnLineStart;
// Get the current line.
_mStrLine = Text.Substring(_mnLineStart, _mNLineLength);

// Process this line.
ProcessLine();

_mBPaint = true;
}
/// <summary>
/// Process a line.
/// </summary>
private void ProcessLine()
{
// Save the position and make the whole line black
int nPosition = SelectionStart;
SelectionStart = _mnLineStart;
SelectionLength = _mNLineLength;
SelectionColor = Color.Black;

// Process the keywords
ProcessRegex(_mStrKeywords, Settings.KeywordColor);
// Process numbers
if(Settings.EnableIntegers)
ProcessRegex("\b(?:[0-9]*\.)?[0-9]+\b", Settings.IntegerColor);
// Process strings
if(Settings.EnableStrings)
ProcessRegex(""[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*"", Settings.StringColor);
// Process comments
if(Settings.EnableComments && !string.IsNullOrEmpty(Settings.Comment))
ProcessRegex(Settings.Comment + ".*$", Settings.CommentColor);

SelectionStart = nPosition;
SelectionLength = 0;
SelectionColor = Color.Black;
}
/// <summary>
/// Process a regular expression.
/// </summary>
/// <param name="strRegex">The regular expression.</param>
/// <param name="color">The color.</param>
private void ProcessRegex(string strRegex, Color color)
{
Regex regKeywords = new Regex(strRegex, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match regMatch;

for (regMatch = regKeywords.Match(_mStrLine); regMatch.Success; regMatch = regMatch.NextMatch())
{
// Process the words
int nStart = _mnLineStart + regMatch.Index;
int nLenght = regMatch.Length;
SelectionStart = nStart;
SelectionLength = nLenght;
SelectionColor = color;
}
}
/// <summary>
/// Compiles the keywords as a regular expression.
/// </summary>
public void CompileKeywords()
{
for (int i = 0; i < Settings.Keywords.Count; i++)
{
string strKeyword = Settings.Keywords[i];

if (i == Settings.Keywords.Count-1)
_mStrKeywords += "\b" + strKeyword + "\b";
else
_mStrKeywords += "\b" + strKeyword + "\b|";
}
}

public void ProcessAllLines()
{
_mBPaint = false;

int nStartPos = 0;
int i = 0;
while (i < Lines.Length)
{
_mStrLine = Lines[i];
_mnLineStart = nStartPos;
_mNLineEnd = _mnLineStart + _mStrLine.Length;

ProcessLine();
i++;

nStartPos += _mStrLine.Length+1;
}

_mBPaint = true;
}
}

/// <summary>
/// Class to store syntax objects in.
/// </summary>
public class SyntaxList
{
public List<string> MRgList = new List<string>();
public Color MColor;
}

/// <summary>
/// Settings for the keywords and colors.
/// </summary>
public class SyntaxSettings
{
SyntaxList m_rgKeywords = new SyntaxList();
string _mStrComment = "";
Color _mColorComment = Color.Green;
Color _mColorString = Color.Gray;
Color _mColorInteger = Color.Red;
bool _mBEnableComments = true;
bool _mBEnableIntegers = true;
bool _mBEnableStrings = true;

#region Properties
/// <summary>
/// A list containing all keywords.
/// </summary>
public List<string> Keywords
{
get { return m_rgKeywords.MRgList; }
}
/// <summary>
/// The color of keywords.
/// </summary>
public Color KeywordColor
{
get { return m_rgKeywords.MColor; }
set { m_rgKeywords.MColor = value; }
}
/// <summary>
/// A string containing the comment identifier.
/// </summary>
public string Comment
{
get { return _mStrComment; }
set { _mStrComment = value; }
}
/// <summary>
/// The color of comments.
/// </summary>
public Color CommentColor
{
get { return _mColorComment; }
set { _mColorComment = value; }
}
/// <summary>
/// Enables processing of comments if set to true.
/// </summary>
public bool EnableComments
{
get { return _mBEnableComments; }
set { _mBEnableComments = value; }
}
/// <summary>
/// Enables processing of integers if set to true.
/// </summary>
public bool EnableIntegers
{
get { return _mBEnableIntegers; }
set { _mBEnableIntegers = value; }
}
/// <summary>
/// Enables processing of strings if set to true.
/// </summary>
public bool EnableStrings
{
get { return _mBEnableStrings; }
set { _mBEnableStrings = value; }
}
/// <summary>
/// The color of strings.
/// </summary>
public Color StringColor
{
get { return _mColorString; }
set { _mColorString = value; }
}
/// <summary>
/// The color of integers.
/// </summary>
public Color IntegerColor
{
get { return _mColorInteger; }
set { _mColorInteger = value; }
}
#endregion
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.