So, I'm making an assembler with a GUI in C#, and I've decided to just make a user control with some syntax highlighting. I'm not very imaginative with names, so I'm just calling it CodeTextBox. Chances are that I'll make it open source once it's done anyway, so I was wondering if anyone was willing to put some effort in to help make it a better control.
So far I've got syntax highlighting working pretty well, and there's no noticeable lag even with hundreds of lines of code. The way I did this was by only updating the syntax on the current line, rather than the entire RTB all at once.
I want it to be simple to change the highlighting that takes place, it currently uses something like this:
Other syntax colors are set pretty easily as well:
And of course you can set the size of the tab key, rather than sending an actual TAB character to the textbox.
Currently the only thing not complete for Syntax Highlighting is comments, mainly because they are multi-line, so I'm trying to work out a way to make that work well. Ideas?
I'm not really having trouble with anything, but I think it could be a good community project if anyone else is bored. So, who's bored?
So far I've got syntax highlighting working pretty well, and there's no noticeable lag even with hundreds of lines of code. The way I did this was by only updating the syntax on the current line, rather than the entire RTB all at once.
I want it to be simple to change the highlighting that takes place, it currently uses something like this:
Code:
txtMain.TheSyntax.ClearSyntax();
txtMain.TheSyntax.AddSyntax(new string[] { ".org", ".word", ".hword", ".align", }, Color.Gray); //Directives
txtMain.TheSyntax.AddSyntax(new string[] { "push", "pop", "mov", "movs", "ldr", "ldrb", "ldrh", "lsl", "lsr", "b", "bx", "bl", "blx", "bge", "beq", "blt", "cmp", "add", "sub" }, Color.Blue); //Keywords
txtMain.TheSyntax.AddSyntax(new string[] { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "lr", "sp", "pc" }, Color.DarkCyan); //Registers
Other syntax colors are set pretty easily as well:
Code:
txtMain.TheSyntax.NumericColor = Color.DarkMagenta;
txtMain.TheSyntax.HighlightNumbers = true;
txtMain.TheSyntax.CommentColor = Color.DarkGreen;
txtMain.TheSyntax.HighlightComments = false;
txtMain.TheSyntax.StringColor = Color.DarkRed;
txtMain.TheSyntax.HighlightStrings = false;
And of course you can set the size of the tab key, rather than sending an actual TAB character to the textbox.
Code:
txtMain.TabSize = 4;
Currently the only thing not complete for Syntax Highlighting is comments, mainly because they are multi-line, so I'm trying to work out a way to make that work well. Ideas?
I'm not really having trouble with anything, but I think it could be a good community project if anyone else is bored. So, who's bored?


















