T
T
temp10012014-11-12 19:48:03
C++ / C#
temp1001, 2014-11-12 19:48:03

How to add line to TextBox C# without autoscroll?

When adding a line to a TextBox Multiline using Environment.NewLine or AppendText, it automatically scrolls down. How to add without autoscroll?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2014-11-12
@v_decadence

If we are talking about WinForms, then

// запоминаем текущую позицию курсора (позицию скролла запомнить нельзя)
int n = textBox1.SelectionStart;
// добавляем текст
// выделяем 0 символов - просто переставляем курсор на старую позицию
textBox1.Select(n, 0);
// и скроллим до него
textBox1.ScrollToCaret();

Will only work if you have a cursor at the current position.

A
Alexander Sydorenko, 2014-11-12
@San40

BUT

textBox1.Select(0, 0);
textBox1.ScrollToCaret();

seems to always work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question