Introduction
Auto-completion & Intellisense are nice features that every developer likes, aren't they? Sadly, there's no such built-in feature as Brackets Autocompletion, so that's why I am proposing this usercontrol in here.
Background
I fell in love with this feature when I used Sublime text editor for the first time , so I am sharing a control that does the same thing.
Implementation
The control contains only 2 objects:
BracketsList
: The array that contains the brackets & symbols that will be auto completed.
AllowAutoComplete
: You can simply set it to true
to activate the feature, or turn it off to disable it.
Using the Code
Easy Usage
- Drag & drop the control on your Form.
- Go to the properties and edit the brackets list.
Dynamic Usage
Exploiting this user control is pretty easy as the following code shows:
(If you want to create a code editor for example, then you'll need to add some regex patterns, etc.)
AutoBracketsTextBox ABTB = new AutoBracketsTextBox();
ABTB.Dock = DockStyle.Fill;
ABTB.BracketsList = new[] { "{" , Environment.NewLine + Environment.NewLine + "}" };
Controls.Add(ABTB);
Samples
Simplest sample.
Simple text editor.
Powerful text editor.
Strings autocomplete sample.
How It Works
InKeyPress
event, if the BracketsList
contains the char
you clicked on, then the ABTB will add the char
next to it into the text (it'll respect the position of the caret).