Before reading and using codes, read the following texts:
- I donβt have enough time to write better codes. I was just trying to write a sample for you.
- I just wrote the codes in a simple way, not in OOP .
- You can improve codes with Enums , Properties , Classes, and other OOP stuff .
- You can improve the logic of codes ; and you can use multi-threading to achieve better performance .
- This example is not exhaustive . I only applied the Auto-Indention example for a semicolon (;) . "
I have to say some tips on using codes:
- rtbCodes is the name of the RichTextBox control in the form in the sample project.
- frmCodeEditor is the name of the form in the sample project.
You can download the sample project at the following addresses:
4Shared -> Auto-Indention for Code Editor
SendSpace -> Auto-Indention for Code Editor
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class frmCodeEditor : Form { char[] chrTracingKeyChars = new char[] { ';', '}', '\n' }; char[] chrCheckingKeyChars = new char[] { '{', '(' }; Point ptCurrentCharPosition; bool bolCheckCalling = false; int intInitialCursorPosition = 0; int intRemainingCharsOfInitialText = 0; int intNextCharIndex = 0; int intPrevCharIndex = 0; public frmCodeEditor() { InitializeComponent(); } private void richTextBox1_TextChanged(object sender, EventArgs e) { AutoIndention(rtbCodes); }
I hope these code examples help you.
Please update and share codes if you improve them.
source share