Vertical scroll Scintilla Textbox during Text Chan

2019-02-16 06:00发布

问题:

Here is a complete VS2010 project to reproduce the problem: http://temp-share.com/show/dPf3aqi7W

Setting a Scintilla.Net textbox with a string and scrolling to last line doesn't work.

This Q & A How make autoscroll in Scintilla? has the answer but it wont work at the same time as setting the text.

Bare bones repro:

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

Does anyone know how to scroll vertically down to end line after setting the text?

回答1:

Well you can try to put Refresh() after adding the text;

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

for this case i found out that you will need to Refresh() twice depend on the length of the string you put on the textbox.



回答2:

For anyone wondering in the end I ditched Scintilla in favor of ICSharpCode.TextEditor. <- This one was a little unstable so I used the Digitalrune version of the ICsharp.TextEditor

I found enhancing the ICSharpCode.TextEditor was trivial compared with Scintilla.

Another huge benefit of ICSharpCode.TextEditor is that allows you to customize/build your own Syntax Highlighting, eg: https://github.com/icsharpcode/SharpDevelop/wiki/Syntax-highlighting