0

Ok, so I was following a guide on how to make a syntax highlighting RichTextBox for a new editor that I'm making, but I'm having a problem with base.WndProc

protected override void WndProc(ref System.Windows.Forms.Message m)
{
    // Code courtesy of Mark Mihevc
    // sometimes we want to eat the paint message so we don't have to see all the
    // flicker from when we select the text to change the color.
    if (m.Msg == 0x00f)
    {
        if (paint)
            base.WndProc(ref m);
        else
            m.Result = IntPtr.Zero;
    }
    else
        base.WndProc(ref m);
}

At the end of the check message statement, I get a stack overflow exception with this:

m = {msg=0x441 (EM_STREAMOUT) hwnd=0x280a8a wparam=0x8011 lparam=0x64e67a0 result=0x0}
m.Msg = 1098
this = {Text = The runtime refused to evaluate the expression at this time}

In the main form, I have this:

private void Box_SelectionChanged(object sender, EventArgs e)
{
    SyntaxTextBox box = (SyntaxTextBox)sender;
    int idx = box.GetLineFromCharIndex(box.SelectionStart);
    int start = box.SelectionStart;
    int len = box.SelectionLength;
    string line = box.Lines[idx];
    Regex r = new Regex(@"[0-9]+", RegexOptions.IgnoreCase|RegexOptions.Compiled);
    SyntaxTextBox.paint = false;
    foreach (Match m in r.Matches(line))
    {
        box.Select(m.Index, m.Value.Length);
        box.SelectionColor = Color.Blue;
        box.SelectionStart = start;
        box.SelectionColor = Color.Black;
    }
    Console.WriteLine(start);
    SyntaxTextBox.paint = true;
}

What's going on with my code?

Mavain
  • 31
  • 4
  • There is very little signal here, other than it being the completely wrong way to do it. Use [this solution](http://stackoverflow.com/a/3282911/17034) instead. – Hans Passant Jul 29 '15 at 11:38
  • Hmm stack overflow didn't give me anything useful for the search before answer stage... This is very helpful! Thank you! :) – Mavain Jul 29 '15 at 18:22

1 Answers1

0

Apparently I was handling it all wrong, and that instead I should use the BeginUpdate and EndUpdate functions and setting the SETREDRAW flag to 0 or 1

Mavain
  • 31
  • 4