Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

c# - Vertical scroll Scintilla Textbox during Text Changed event

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...