Click here to Skip to main content
15,118,865 members
Articles / Programming Languages / C#
Posted 3 Apr 2016


9 bookmarked

AutoBracketsTextBox for brackets auto-completion

Rate me:
Please Sign up or sign in to vote.
4.76/5 (23 votes)
16 Apr 2016LGPL31 min read
Enable brackets & symbols autocompletion

Image 1


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.


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.


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

  1. Drag & drop the control on your Form.
  2. Go to the properties and edit the brackets list.

Image 2

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 + "}"  };


Simplest sample.

Image 3

Simple text editor.

Powerful text editor.

Image 4

Strings autocomplete sample.

Image 5

How It Works

In KeyPress 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).

Image 6


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


About the Author

Alaa Ben Fatma
France France
No Biography provided

Comments and Discussions

GeneralGreat... Pin
Pritam Zope1-May-16 11:09
MemberPritam Zope1-May-16 11:09 
GeneralRe: Great... Pin
Alaa Ben Fatma7-May-16 5:44
professionalAlaa Ben Fatma7-May-16 5:44 
GeneralMy vote of 5 Pin
Dmitriy Gakh11-Apr-16 23:57
professionalDmitriy Gakh11-Apr-16 23:57 
GeneralRe: My vote of 5 Pin
Alaa Ben Fatma12-Apr-16 9:39
professionalAlaa Ben Fatma12-Apr-16 9:39 
Questionusing this program Pin
Member 124336643-Apr-16 10:23
MemberMember 124336643-Apr-16 10:23 
AnswerRe: using this program Pin
Alaa Ben Fatma3-Apr-16 10:55
professionalAlaa Ben Fatma3-Apr-16 10:55 
QuestionQuestion Pin
Mohamed Aziz Lahbecha3-Apr-16 11:02
MemberMohamed Aziz Lahbecha3-Apr-16 11:02 
AnswerRe: Question Pin
Alaa Ben Fatma4-Apr-16 12:00
professionalAlaa Ben Fatma4-Apr-16 12:00 
GeneralMy vote of 5 Pin
Member 124336643-Apr-16 6:57
MemberMember 124336643-Apr-16 6:57 
GeneralMy vote of 5 Pin
Member 124336663-Apr-16 6:56
MemberMember 124336663-Apr-16 6:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.