Vertical scroll Scintilla Textbox during Text Changed event

…衆ロ難τιáo~ 提交于 2019-11-30 21:20:04

问题


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



来源:https://stackoverflow.com/questions/16158780/vertical-scroll-scintilla-textbox-during-text-changed-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!