Jump to content

[C# ~ User Control] Richtextbox w/ modifiable syntax highlighting and line numbers :D

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
charless

charless

    Newbie

  • Members
  • PipPip
  • 14 posts
So I made this user control that I thought somebody may find usefull :)
Its a user control.
Its a richtextbox, with modifiable syntax highlighting and line numbers :D
Its easy to use, once you import it, just drag it onto your form :D to modify the syntax hiighlighting is simple, as an example here's what I did for the example app (C#) highlighting:
            string[] kw = { "int", "bool", "string", "object", "false", "true", "byte", "char", "return", "public", "void", "static", "private", "class", "namespace", "using", "partial", "override","for","if","while","do","else","break","case"};
            codeBox1.AKeyWords1 = kw;
            string[] kw2 = { "!@#$%^&*(" };
            codeBox1.AKeyWords2 = kw2;
            string[] kw3 = { "!@#$%^&*(" };
            codeBox1.AKeyWords3 = kw3;
            codeBox1.CommentBegin = "//";

Keywords1 is blue text
Keywords2 is Red text and Bold
Keywords3 is Purple text and Italic

I put "!@#$%^&*(" for keywords1 & 2 because I didn't need keywords 1 & 2, if you leave it blank it will use default keywords, so if you dont need them, just put random crap in ;)

To access the text use:
codeBoxName.TheText
just Text won't cut it, sorry :(

Here's a screeny of how it looks:
Posted Image
Here's the download for the user control, I did a template export thing:
Code_Box_UC.zip
Here's a pre compiled example, all it is is the contorl on a form with a full dock, for those of you who dont feel like making your own test ;), syntax highlighting is C#:
Code_Box Example.exe

Use it if you think it'll help you, I'd appreciate a PM telling about its use if you though, and if its comercial I wouldn't say no to a free copy :D (although I doutb anybody would use this in anything comercial, although u never know! )

~Charless

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Now that could be very handy :)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
g-man122

g-man122

    Newbie

  • Members
  • PipPip
  • 29 posts
Great work, and fantastic for learning. +rep.

#4
charless

charless

    Newbie

  • Members
  • PipPip
  • 14 posts
Thanks g-man122 :) but what does rep do?
This is still very glitchy, and Ill update it when I get the time, the biggest problem is the line numbers, the line numbers are slightly offset, once you get past ~line 80 or so, it become significant, like in it should say line 127 but says line 116, but I still think its a good base for something better.
It also doesn't have support for pre highlighting text, it current only highlights the line your editing, you cant insert text, for example from a file, and have it highlight the whole thing, without making ajustments.
It currently only uses a basic tokenizer, Im hoping eventually to implament some Regex functionlity for syntax highlighting of things like variable, and strings.

#5
g-man122

g-man122

    Newbie

  • Members
  • PipPip
  • 29 posts

charless said:

Thanks g-man122 :) but what does rep do?
This is still very glitchy, and Ill update it when I get the time, the biggest problem is the line numbers, the line numbers are slightly offset, once you get past ~line 80 or so, it become significant, like in it should say line 127 but says line 116, but I still think its a good base for something better.
It also doesn't have support for pre highlighting text, it current only highlights the line your editing, you cant insert text, for example from a file, and have it highlight the whole thing, without making ajustments.
It currently only uses a basic tokenizer, Im hoping eventually to implament some Regex functionlity for syntax highlighting of things like variable, and strings.

Rep is reputation, the more rep the better, I suppose :P.

And it would be nice to see a final version of this, too.