Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Stopping a multi-line textbox from scrolling back to the top after refresh???

 

I've got a problem that's really racking my brains here. Hoping someone can help me out. Ok, I've got a Multi-line textbox. I'm using a background thread to continously add new text to it (textbox.text = textbox.text + newtext). Everytime the new text gets added the textbox refreshes, causing the textbox to scroll back to the top. I don't want the textbox to scroll back to the top. I need it to stay whereever the user scrolls the text to.

Any ideas on this one at all? I've googled it to death and haven't come up with much at all.

Edited by AlteredImage
Posted

Lets be the proverbial pain in the *** and point out that doing GUI stuff on the wrong thread can result in strange results, check with textbox.InvokeRequired. If it returns true you're not on the GUI thread and shouldnt even change properties of the control.

 

But since I can also be usefull, take a look at the TextBox.SelectionStart and SelectionLength properties. A selectionlength of 0, and a start that is the length of the total string displayed should do the trick.

Nothing is as illusive as 'the last bug'.
Posted

Fixed...and better even. ;)

 

Just wanted to thank you guys for your thoughts on threading.

What I did to fix it was I just used the "append" method of the textbox!

This alowed me add text without having to completely redraw everything, thus preventing the textbox from snapping back to the top.

 

Duh... I Kick myself in the butt for being so dumb. :rolleyes:

 

Thanks again. ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...