 |
|
|
 |
|
 |
Hi,
can you please post also the extra function for the comments.
Thanks
|
|
|
|
 |
|
 |
well, I changed the code again and now its very simple:
now i use the old methode for integers, strings and commentsprivate void ProcessRegex(string strRegex, Color color)
{
Regex regKeywords = new Regex(strRegex, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match regMatch;
for (regMatch = regKeywords.Match(m_strLine); regMatch.Success; regMatch = regMatch.NextMatch())
{
int nStart = m_nLineStart + regMatch.Index;
int nLenght = regMatch.Length;
SelectionStart = nStart;
SelectionLength = nLenght;
SelectionColor = color;
}
}
and just the new one for highlightingprivate void HighLightRegex(string strRegex, Color color)
{
Regex regKeywords = new Regex(@"\w+", RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match regMatch;
for (regMatch = regKeywords.Match(m_strLine); regMatch.Success; regMatch = regMatch.NextMatch())
{
string keyword;
if (Settings.Keywords.TryGetValue(regMatch.Value, out keyword))
{
int nStart = m_nLineStart + regMatch.Index;
int nLenght = regMatch.Length;
SelectionStart = nStart;
SelectionLength = nLenght;
SelectionColor = color;
}
}
}
it's still faster then the original code, because the comments, integers and strings aren't using the keywords.
Also I changed the strRegex for strings. Now it also highlights chars (e.g. 'a'):"(\"[^\"\\\\\\r\\n]*(?:\\\\.[^\"\\\\\\r\\n]*)*\"|\'[^\'\\\\\\r\\n]*(?:\\\\.[^\'\\\\\\r\\n]*)*\')"
if there is an easier way: post reply, please
no_morser
|
|
|
|
 |
|
 |
Hello,
I'm trying to add your new code. But now I've got the problem, that the line with "TryGetValue" occurs an error:
Error1 "System.Collections.Generic.List" has now definition for "TryGetValue",and there is no expanded method with "TryGetValue" found in the code, there is no argument "System.Collections.Generic.List" accepted. (Maybe there are some missing Using-Directive or Assembly?)
the using-directive "using System.Collections.Generic;" is set, so maybe you know whats wrong? Or you update you Download-Code to see whats wrong (Maybe I placed it wrong?!? (I place your new routine right after the old one)
Best regards
Tim
|
|
|
|
 |
|
 |
Can you explain more about this string: "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\""
Thanks
Tran Ho Le NGuyen
|
|
|
|
 |
|
 |
just like visual studio highlight, the functions are highlighted in different colors as keywords.
it is easy to add this term.
|
|
|
|
 |
|
 |
Hi.
I'm using your excellent control inside my editor.
I've just dragged it to my MainForm and I've registered a method (MainForm_TextChanged)to the TextChanged event.
Then I've implemented MainForm_TextChanged.
But it seems that the application doesn't reach this method when I changes the text of the SyntaxRichTextBox. Do you have any idea what privents MainForm of listening to the TextChanged event?
|
|
|
|
 |
|
 |
at the end of the OnTextChanged event put base.OnTextChanged(e);
|
|
|
|
 |
|
 |
hi, i love this control and i use it in my app.
but my apps users have reported that the textbox highlights a little too slow.
are u planning on a new release better performane?
_____________________________
Don't download it, make it.
Visual Basic /C#
|
|
|
|
 |
|
 |
I really need this one. fortunately I found in my first search from google.
Again, Thanks a lot for sharing.
dnpro
"Very bad programmer"
|
|
|
|
 |
|
 |
What license is the code released under?
Thanks.
|
|
|
|
 |
|
 |
The do-whatever-you-want-licence.
"If knowledge can create problems, it is not through ignorance that we can solve them." Isaac Asimov
|
|
|
|
 |
|
|
 |
|
 |
Is there any way to background highlight a line if it STARTS WITH "fox", then highlight the entire line AS THE USER IS TYPING ?
|
|
|
|
 |
|
 |
Thank you for the control; it's great. I gave you a 5.
BTW, I used your control in my application and I gave you credit at the bottom of the article. You can check out the article here: http://www.codeproject.com/KB/recipes/EvaluationEngine.aspx
Donald.
|
|
|
|
 |
|
 |
How can I undo and redo in SyntaxRichTextBox?
Please help me...
This is my signature.
|
|
|
|
 |
|
 |
Hi,
To solve Redo/Undo problem:
Use TextEditorControl_KeyUp event instead of TextEditorControl_TextChanged or TextEditorControl_KeyPress events.
Now, Redo/Undo works.
To bypass Redo/Undo selection steps, REWRITE a NEW Undo/Redo and DO base.Undo/base.Redo until Text property changes.
|
|
|
|
 |
|
 |
I do not really think that you need to rewrite the REDO or UNDO.
// <summary>
/// OnTextChanged
/// </summary>
/// <param name="e"></param>
protected override void OnKeyUp(KeyEventArgs e)
{
if (!e.Control)
{
m_nContentLength = this.TextLength;
int nCurrentSelectionStart = SelectionStart;
int nCurrentSelectionLength = SelectionLength;
m_bPaint = false;
// Find the start of the current line.
m_nLineStart = nCurrentSelectionStart;
while ((m_nLineStart > 0) && (Text[m_nLineStart - 1] != '\n'))
m_nLineStart--;
// Find the end of the current line.
m_nLineEnd = nCurrentSelectionStart;
while ((m_nLineEnd < Text.Length) && (Text[m_nLineEnd] != '\n'))
m_nLineEnd++;
// Calculate the length of the line.
m_nLineLength = m_nLineEnd - m_nLineStart;
// Get the current line.
m_strLine = Text.Substring(m_nLineStart, m_nLineLength);
// Process this line.
ProcessLine();
m_bPaint = true;
}
else if (e.KeyCode == Keys.Z)
{
base.OnKeyUp(e);
}
}
should be solving the problem, this is just a quick answer, you might find better idea to solve the problem
|
|
|
|
 |
|
 |
What if you are using html as syntax...
i tried "<html>" & "<html" both... i think "<" is not working..
I was using this RTF Box in a small html editor and taking preview on a WebBrowser, i tried to used TextChanged Event, the Event is not working the Break point on this point doesnt get a hit on text changed.
is it right?
--
ASif Ashraf
MCAD.Net,MCP
Asif.Log@gmail | hotmail.com
92-306-4526526
Sr. dotNet & Flash Developer
Blu Media Works LHR PK
|
|
|
|
 |
|
 |
Probably not.
"If knowledge can create problems, it is not through ignorance that we can solve them." Isaac Asimov
|
|
|
|
 |
|
 |
hmmm..
thats fine.. no problem ....
anyhow i checked and it dint work fine with me.. maybe my own fault... i just added keywords and did nothing else....
bye
--
ASif Ashraf
MCAD.Net,MCP
Asif.Log@gmail | hotmail.com
92-306-4526526
Sr. dotNet & Flash Developer
Blu Media Works LHR PK
|
|
|
|
 |
|
 |
I am using this code as the base of my syntax highlighter and there are several things that i've done to reduce loading time. Here is something you can do:
1. Process line when user hits space bar, rather than having it processed as a new char gets added.
2. Preload regular expressions. I have a DLL with all of my regular expressions in it. The dll is loaded once on start-up and then used throughout the code so that you don't create a new regex instance while abandoning the previous one.
3. Use standard RichTextBox operations to perform line calculations instead of doing everything in loops.
4. When processing a line, split it by empty space and use a for each loop to traverse through a line looking for keywords. This is more efficient than using for loops. I also used a balanced binary tree to store keywords which have already been highlighted and the position of their last character. This way, if i have a duplication keyword on one line i can keep track of them.
All of this reduced loading time significantly. You could also put some operations in threads if you wanted an even better performance.
|
|
|
|
 |
|
 |
How does one go about using adding these optimizations... Im kinda new at this.
|
|
|
|
 |
|
 |
How I Process line when user hits space bar?
This is my signature.
|
|
|
|
 |
|
 |
To implement Space bar and return processing instead of every char add:
private Keys lastKeycode;
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
lastKeycode = e.KeyCode;
if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Space)
{
TextHasChanged();
}
}
Cut the code under OnTextChanged and place it under a new method TextHasChanged
private void TextHasChanged()
{
if (lastKeycode == Keys.Return)
{
SelectionStart -= 1;
}
//paste OnTextChanged Code here
//copied code
//paste OnTextChanged Code here
ProcessLine();
if (lastKeycode == Keys.Return)
{
SelectionStart += 1;
}
m_bPaint = true;
}
Works for me
|
|
|
|
 |