Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
2.60/5 (3 votes)
See more:
Fast Colored TextBox for Syntax Highlighting[^]

I'm using the above control for a custom syntax highlighter. I'm trying to dynamically update the styles used. When I look at the example, it changes color when the TextChangedDelayed event is fired, but when I implement similar code, it changes color and then changes the text:

Example:
fctb.Range.ClearStyle(KeywordsStyle, FunctionNameStyle);
            //highlight keywords of LISP
            fctb.Range.SetStyle(KeywordsStyle, @"\b(and|eval|else|if|lambda|or|set|defun)\b", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //find function declarations, highlight all of their entry into the code
            foreach (Range found in fctb.GetRanges(@"\b(defun|DEFUN)\s+(?<range>\w+)\b"))
                fctb.Range.SetStyle(FunctionNameStyle, @"\b" + found.Text + @"\b");


My Code:
fctb.Range.ClearStyle(FnDynamic, VarDynamic);
            //find function declarations, highlight all of their entry into the code
            foreach (Range found in fctb.GetRanges(@"\bprocess\s+(?<range>\w+)\b"))
                fctb.Range.SetStyle(FnDynamic, @"\b" + found.Text + @"\b");
            foreach (Range found in fctb.GetRanges(@"\bvariable\s+(?<range>\w+)\b"))
                fctb.Range.SetStyle(VarDynamic, @"\b" + found.Text + @"\b");
            foreach (Range found in fctb.GetRanges(@"\bfor\s+(?<range>\w+)\b"))
                fctb.Range.SetStyle(VarDynamic, @"\b" + found.Text + @"\b");


I implement this control using System.Windows.Forms.Integration.WindowsFormsHost, so it should work the same (I think). Instead, it seems like the same event (TextChangedDelayed) is firing at different times in WPF (Before the text is written to the screen) than in windows forms (After the text is written to the screen an the user has stopped typing).

Any ideas as to why this would happen?

Thanks!
Posted
Updated 16-Jan-14 3:21am
v2
Comments
Sergey Alexandrovich Kryukov 15-Jan-14 23:31pm    
This is not a valid question. The article you referenced is about the code based on System.Windows.Forms, and System.Drawing. It is absolutely unclear why would you expect that WPF worked in the same way when you have wrote some code based on your understanding of it. We have no idea what your code does and why you wrote it the way you did. You did not really describe any real problem. If you ask "why this would happen", you would need to explain what is "this".
—SA
ZurdoDev 16-Jan-14 10:01am    
They are different. I don't know if what you see is default behavior but WPF and Windows Forms are obviously different so I would not be surprised that they act different.
bowlturner 16-Jan-14 10:01am    
WPF is a completely different paradigm to windows forms. I wouldn't expect any windows forms controls to work the same in WPF. WPF has many of it's own controls and usually has an even better way to do what ever you want from a Windows form control.
(Username_Taken) 16-Jan-14 20:15pm    
That's true, but this is the only good open-source syntax highlighter I could find (I have too many time constraints to make my own), and it happens to be a windows forms control.
Philippe Mori 16-Jan-14 23:02pm    
Why create a new question instead of asking original article author?

Maybe the best option would be to rewrite code for WPF.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900