Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

AutoBracketsTextBox for brackets auto-completion

0.00/5 (No votes)
16 Apr 2016 1  
Enable brackets & symbols autocompletion

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.

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here