C#base.WndProc StackOverflowException /运行时表达式拒绝

时间:2015-07-29 10:41:46

标签: c# windows

好的,所以我正在按照指南说明如何为我正在制作的新编辑器突出显示RichTextBox,但我遇到了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);
}

在检查消息语句结束时,我得到了一个堆栈溢出异常:

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}

在主要表格中,我有这个:

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;
}

我的代码发生了什么?

1 个答案:

答案 0 :(得分:0)

显然我处理的都错了,而我应该使用BeginUpdate和EndUpdate函数并将SETREDRAW标志设置为0或1