How can I code two buttons for scrolling into a RichTextBox up and down ? What I try :
private void btnScrollTop_Click(object sender, EventArgs e) {
if (rtbDefinitie.SelectionStart >= 30) {
rtbDefinitie.SelectionStart -= 30;
rtbDefinitie.ScrollToCaret();
}
}
private void btnScrollBottom_Click(object sender, EventArgs e) {
if (rtbDefinitie.SelectionStart <= 30) {
rtbDefinitie.SelectionStart += 30;
rtbDefinitie.ScrollToCaret();
}
}
But it’s seems to get stuck after I press scroll down button twice. What I need to do ?
The second click seems to be interpreted as DoubleClick, so you could just register this event too and put the same code behind it (or replace the
30by60)EDIT:
If the Application stucks, because it’s working and does not have the time to update the GUI, you could try to call
Application.DoEvents();after every raised Clickevent: