TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Florin Richardson
NA
2
4.1k
Hide focused richtextbox blue selection
Jan 10 2013 12:48 PM
I am doing a syntax highlighter (which is my first c# project) and I have some performance problems.
Every time I have to color a word, I stop the repaint, color the word, enable repaint and invalidate the richtextbox.
This is the richtextbox class:
namespace test
{
class rtb:RichTextBox
{
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
private const int WM_SETREDRAW = 0x0b;
public void BeginUpdate()
{
SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
}
public void EndUpdate()
{
SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
this.Invalidate();
}
}
}
The invalidation (refresh) causes, sometimes, some rows of text to flicker, which is unpleasant. If I don't stop the repaint and color the words directly, the blue selection of the word is visible.
I color the words with this method :
private void doPaint(int start, int length, Color selColor)
{
rtb1.BeginUpdate(); // rtb1 is the richtextbox (from rtb class)
rtb1.SelectionStart = start;
rtb1.SelectionLength = length;
rtb1.SelectionColor = selColor;
rtb1.SelectionLength = 0;
rtb1.EndUpdate();
}
How can I hide that blue selection, while the user is typing, and color the word? If that is not possible, how can I stop that small flicker caused by the refreshing of the richtextbox?
Thank you in advance !
Reply
Answers (
0
)
Help me solve this math , algorithm problem. Really interest
Sorting Output of Individual Integers C#