Tuesday, 19 May 2009

Multiline Textbox update with autoscroll and less flashing in VB

I'll never remember this one, so here's the scenario.

Flaky code reading single bytes from a network stream, want a multiline textbox to show the output live. Problem is the cursor is at the top and text appends to the bottom. If I force the cursor to the bottom with textbox.scrolltocaret it's well flashy. Simple answer, don't add to the textbox.text, append to the box itself thus:

BAD
textbox.text=textbox.text & "stuff"
textbox.refresh
textbox.scrolltocaret

BETTER
textbox.SelectionStart = outputbox.TextLength
textbox.SelectedText = "stuff"

No comments:

Post a Comment