【问题标题】:Vertical scroll Scintilla Textbox during Text Changed event文本更改事件期间垂直滚动闪烁文本框
【发布时间】:2013-04-23 00:06:45
【问题描述】:

使用字符串设置 Scintilla.Net 文本框并滚动到最后一行不起作用。

此问答How make autoscroll in Scintilla? 有答案,但它不会在设置文本的同时起作用

裸骨再现:

private void button1_Click(object sender, EventArgs e)
{
    string s = RandomString(400);
    scintilla1.Text = s + " " + s + " " + s + " " + s + " " + s;
    scintilla1.Scrolling.ScrollBy(0, 10000);    //<-doesn't work (but does work eg in a Button2_click)
}

private static Random random = new Random((int)DateTime.Now.Ticks);
private string RandomString(int size)
{
    StringBuilder builder = new StringBuilder();
    char ch;
    for (int i = 0; i < size; i++)
    {
        ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
        builder.Append(ch);
    }
    return builder.ToString();
}

有谁知道设置文本后如何垂直向下滚动到结束行?

【问题讨论】:

    标签: c# .net scroll scintilla


    【解决方案1】:

    好吧,你可以尝试在添加文本后放入 Refresh();

    scintilla1.Text = s + " " + s + " " + s + " " + s + " " + s;
    scintilla1.Refresh();

    对于这种情况,我发现您需要 Refresh() 两次,具体取决于您放在文本框上的字符串的长度。

    【讨论】:

    • 说真的,我现在就试一试。它奏效了,谢谢 Hendrik - YOU'LL WILL BE A C# MVP SOON!hehe
    • 谢谢伙计。我还需要学习很多东西,你们提供解决方案真是太棒了。
    【解决方案2】:

    对于任何想知道我最终放弃 Scintilla 转而支持 ICSharpCode.TextEditor 的人。 Digitalrune version of the ICsharp.TextEditor

    我发现enhancing the ICSharpCode.TextEditor 与 Scintilla 相比微不足道。

    ICSharpCode.TextEditor 的另一个巨大好处是允许您自定义/构建自己的语法突出显示,例如:https://github.com/icsharpcode/SharpDevelop/wiki/Syntax-highlighting

    【讨论】:

      猜你喜欢
      • 2010-12-05
      • 2016-10-06
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多