|
-
Oct 28th, 2006, 06:10 AM
#1
Thread Starter
Member
[RESOLVED] View end of text after new text
Hi there,
I have a text on a textobox and append some new one by using
TextBox1.Text = TextBox1.Text & vbNewLine & "new string"
When i do that sometimes the new text exceeds the lines of the textbox so i need the scrollbars to look through all of it.
The problem is that when i get new text the textbox automatically scrolls all the way up. I want the scrollbar to stay at the end so i can see the new text directly.
How can i do that?
NOTE: I am programmin on the compact framework, programmin for a pda.
Thanks
-
Oct 28th, 2006, 06:24 AM
#2
Re: View end of text after new text
Don't add text to a TextBox like that. Use its AppendText method, which will also sort out the issue you are having with scrolling.
-
Oct 28th, 2006, 09:05 AM
#3
Re: View end of text after new text
It is also more preferable to use instead of vbNewLine
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 28th, 2006, 12:40 PM
#4
Thread Starter
Member
Re: View end of text after new text
I am using the compact framework, programming for my pda so Append doesnt exist on the TextBox methods. Neither Enviroment.Newline exists.
Any other ideas?
-
Oct 28th, 2006, 09:59 PM
#5
Re: View end of text after new text
I haven't actually dealt with this in the CF, but I have a question, and maybe a suggestion.
Am I correct in reading your original post to mean that you have the scrollbar, scroll to the end, add text, and the scrollbar automatically snaps back to the top?
The CF is a weird place to work, and some of the solutions are not at all obvious. If the textbox default behavior is not to your liking, see whether or not there is a bizarre alternative using multiple controls. As an example, there is no multi-select listbox in the CF. I got around this by adding a panel with a scroll bar. On the panel, I added a bunch on small panels with labels on them. I then filled the labels from an array of strings, starting with the array index of the scroll bar value. While it was a weird way to do things, it worked great, and looked just like a multi-select listbox.
In your case, it appears fairly obvious that when you add text, the textbox control is being set back to a default state, but what is that default state? If you were to implement a textbox with other types of controls, you might have a panel with a label on it (to hold the text), and a scrollbar on it. The difficulty would be in linking the scrollbar value to what text you start writing in the label. You could use the same technique that I did for the multi-select list box, as long as you can figure out the word wrap of the text yourself. This could be done by holding the string in a custom class that fed out the string in chunks of size x, where x is the length of the label, and where each chunk is terminated by a space, and is less than or equal to x.
This solution could be a slow one to implement, but it would work. If labels wrap words themselves (they do don't they? I can't remember), then you would only need one label on the panel, and get the substring of the main string based on the width of the label times the value of the scrollbar (5 label widths would be the sixth line down, and if the scrollbar had the value of 0, you would start with main string.substring(0)).
If nobody has a direct solution for your problem, I'd be looking at a goofy solution like that, with a panel, a label, and a scrollbar. If that failed, I'd be looking at a panel with multiple one-line panels with labels on them, a scrollbar, and a class in the background feeding lines to the labels.
My usual boring signature: Nothing
 
-
Oct 28th, 2006, 10:01 PM
#6
Re: View end of text after new text
Ah, apologies. Given that there's a .NET Mobile Development forum it's generally better to post CF questions there, although you did specify you were using the CF so I should have noticed.
In that case do this:
VB Code:
myTextBox.Text &= newText
myTextBox.SelectionStart = myTextBox.Text.Length
myTextBox.ScrollToCaret()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|