Click here to Skip to main content
15,867,308 members
Articles / Programming Languages / C#

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 19.4K   374   9   11
Enable brackets & symbols autocompletion

Image 1

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

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

C#
AutoBracketsTextBox ABTB  = new AutoBracketsTextBox();
ABTB.Dock = DockStyle.Fill;
ABTB.BracketsList = new[] {  "{" ,  Environment.NewLine + Environment.NewLine + "}"  };
Controls.Add(ABTB);

Samples

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

License

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


Written By
Student
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat... Pin
Pritam Zope1-May-16 10:09
Pritam Zope1-May-16 10:09 
GeneralRe: Great... Pin
Alaa Ben Fatma7-May-16 4:44
professionalAlaa Ben Fatma7-May-16 4:44 
GeneralMy vote of 5 Pin
Dmitriy Gakh11-Apr-16 22:57
professionalDmitriy Gakh11-Apr-16 22:57 
GeneralRe: My vote of 5 Pin
Alaa Ben Fatma12-Apr-16 8:39
professionalAlaa Ben Fatma12-Apr-16 8:39 
Questionusing this program Pin
Member 124336643-Apr-16 9:23
Member 124336643-Apr-16 9:23 
AnswerRe: using this program Pin
Alaa Ben Fatma3-Apr-16 9:55
professionalAlaa Ben Fatma3-Apr-16 9:55 
QuestionQuestion Pin
Mohamed Aziz Lahbecha3-Apr-16 10:02
Mohamed Aziz Lahbecha3-Apr-16 10:02 
AnswerRe: Question Pin
Alaa Ben Fatma4-Apr-16 11:00
professionalAlaa Ben Fatma4-Apr-16 11:00 
GeneralMy vote of 5 Pin
Member 124336643-Apr-16 5:57
Member 124336643-Apr-16 5:57 
montassar riahi
GeneralMy vote of 5 Pin
Member 124336663-Apr-16 5:56
Member 124336663-Apr-16 5: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.