Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

syntax

  • Please log in to reply
4 replies to this topic

#1 charless

charless

    CC Newcomer

  • Just Joined
  • PipPip
  • 14 posts

Posted 29 December 2009 - 06:57 PM

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 ** 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
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 30 December 2009 - 05:44 AM

Now that could be very handy :)
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 g-man122

g-man122

    CC Regular

  • Just Joined
  • PipPipPip
  • 25 posts

Posted 30 December 2009 - 12:34 PM

Great work, and fantastic for learning. +rep.
  • 0

#4 charless

charless

    CC Newcomer

  • Just Joined
  • PipPip
  • 14 posts

Posted 30 December 2009 - 01:03 PM

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.
  • 0

#5 g-man122

g-man122

    CC Regular

  • Just Joined
  • PipPipPip
  • 25 posts

Posted 31 December 2009 - 05:59 AM

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.
  • 0





Also tagged with one or more of these keywords: syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download