Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need a control for good scrolling status output

2 views
Skip to first unread message

djc

unread,
Feb 28, 2006, 10:57:06 AM2/28/06
to
I'm looking for a way to display text information on a windows forms app in
a way that as new information is added the newest info is always visible.
The best way to explain is this:

A regular textbox control would work perfectly fine for me if only as I
append text to it, it scrolled to the bottom so the newly added info is
visible and older info can scroll off the top of the textbox.

can I make a text box do this? or is there another control I could use to do
this? I need a control to use as an output screen that will be coninually
written to by several other components of the program. A 'status' output, if
you will.

any input would be greatly appreciated, thanks.


Kevin Spencer

unread,
Feb 28, 2006, 1:30:55 PM2/28/06
to
Check out the TextBox.SelectionStart property, the TextBox.SelectionLength
property, and TextBox.ScrollToCaret() method. And remember that if you want
to make use of these you have to put the focus on the TextBox.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
A brute awe as you,
a Metallic hag entity, eat us.


"djc" <no...@nowhere.com> wrote in message
news:eXHCh%23HPGH...@TK2MSFTNGP09.phx.gbl...

djc

unread,
Feb 28, 2006, 1:38:48 PM2/28/06
to
I'll check them out. Thanks.

"Kevin Spencer" <ke...@DIESPAMMERSDIEtakempis.com> wrote in message
news:%23NngeUJ...@TK2MSFTNGP09.phx.gbl...

Cerebrus

unread,
Feb 28, 2006, 11:41:17 PM2/28/06
to
Hi djc,

This code may not be highly performant, but it works. Note: This uses
the Lines property of the textbox, so in order to recognize that text
has been appended, you need to add it on a new line (after CrLf)

For best results, set the vertical size of the Textbox such that it
only the required no. of lines is visible. I had to use a Boolean
variable "working" to prevent recursion, since changing the text within
the sub triggers the TextChanged event again.

I am also open to comments on how this code can be improved.

------------------------------------------------------
Dim MaxLines as Integer = 10
Dim LineCount As Integer
Dim working As Boolean = False

Private Sub Txt1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Txt1.TextChanged
If working = True Then
Exit Sub
Else
'First count the no. of lines in the textbox
LineCount = Txt1.Lines.GetUpperBound(0)
If LineCount > MaxLines Then
working = True
Dim arrLines() As String = Txt1.Lines
'Txt1.
Dim i As Integer
Dim currText As String
'Remove the first line and leave all other text intact.
For i = 1 To (arrLines.GetUpperBound(0) - 1)
currText += arrLines(i) & vbCrLf
Next
Txt1.Text = currText
'Position the caret at the bottom of the text.
Txt1.SelectionStart = Txt1.Text.Length
Txt1.ScrollToCaret()
working = False
End If
End If
End Sub

------------------------------------------------------

HTH,

Regards,

Cerebrus.

djc

unread,
Mar 1, 2006, 3:20:02 PM3/1/06
to
thank you.

"Cerebrus" <zor...@sify.com> wrote in message
news:1141188077.5...@e56g2000cwe.googlegroups.com...

0 new messages