Perpetual Scrolling Window

G

Guest

Hi all,

Is it possible to do a console like scrolling window in a Windows Form app?

The closest I've gotten is to use a RichTextBox and append text to it.

However, after a while, there is too much text, I need to clear the textbox
- this causes the screen to flash and I lose all prior text.

Is there a good method of keeping only X lines in a RichTextBox?

Logs could be coming in quickly ... so are there any high performance
methods of doing this?
 
L

Lloyd Sheen

Spam Catcher said:
Hi all,

Is it possible to do a console like scrolling window in a Windows Form
app?

The closest I've gotten is to use a RichTextBox and append text to it.

However, after a while, there is too much text, I need to clear the
textbox
- this causes the screen to flash and I lose all prior text.

Is there a good method of keeping only X lines in a RichTextBox?

Logs could be coming in quickly ... so are there any high performance
methods of doing this?

This might be overkill but I have used a virtual list ListView control to do
somewhat the same. If you have a data store of anykind that can feed t he
ListView you can then set the ListView to virtual and set the count to the
number of items in your data store. At that point the listview will start
firing (sorry not close to VS) an event asking you to provide a
ListViewItem. In this routine (think of it as the binding routine) you get
the item number which in most cases would be an index into your data store.
You can sort this by sorting your data store and then reseting the count.
There are other events to handle selections but in most cases you won't need
to deal with them. When you handle an item click in the ListView you again
get the index so you should have a helper function to get the item from the
data store.

Hope this gets you started. I have an app that loads about 25K items into
10 virtual listboxs on app startup. Items are serialized objects and the
app takes about 1-2 secs to load all the data. Before I used virtual
ListView it took about 10-15 seconds.

Lloyd Sheen
 
L

Lloyd Sheen

Spam Catcher said:
Hi all,

Is it possible to do a console like scrolling window in a Windows Form
app?

The closest I've gotten is to use a RichTextBox and append text to it.

However, after a while, there is too much text, I need to clear the
textbox
- this causes the screen to flash and I lose all prior text.

Is there a good method of keeping only X lines in a RichTextBox?

Logs could be coming in quickly ... so are there any high performance
methods of doing this?

One more thing, if you use a listview you can always ensure that the last
item added is visible by just setting the ensurevisible property when you
create the listviewitem

Lloyd Sheen
 
R

rowe_newsgroups

Hi all,

Is it possible to do a console like scrolling window in a Windows Form app?

The closest I've gotten is to use a RichTextBox and append text to it.

However, after a while, there is too much text, I need to clear the textbox
- this causes the screen to flash and I lose all prior text.

Is there a good method of keeping only X lines in a RichTextBox?

Logs could be coming in quickly ... so are there any high performance
methods of doing this?

I was just playing around with this and it seems to not do to bad
performance wise. Hopefully it will help you out:

Public Class FlashlessRTB ' Though it's not quite flashless :)
Inherits RichTextBox

Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
End Sub

Private _MaxLines As Integer = 10
Public Property MaxLines() As Integer
Get
Return _MaxLines
End Get
Set(ByVal value As Integer)
_MaxLines = value
End Set
End Property

Public Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
MyBase.Text = value
TrimLines()
End Set
End Property

Public Sub TrimLines()
While Me.Lines.Length > MaxLines
Try
preventPainting = True
Me.Text = Me.Text.Substring(Me.Lines(0).Length + 1,
Me.Text.Length - (Me.Lines(0).Length + 1))
Me.SelectionStart = Me.Text.Length
Finally
preventPainting = False
End Try
End While
End Sub

Private preventPainting As Boolean = False

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
' Kill any WM_PAINT messages
If (Not preventPainting OrElse m.Msg <> &HF) Then
MyBase.WndProc(m)
End If
End Sub

End Class

Let me know how it works out.

Thanks,

Seth Rowe
 
G

Guest

This might be overkill but I have used a virtual list ListView control
to do somewhat the same.

I had thought about using a ListView too - but each row can only have 1 row
of text right? Unfortunately some of my log messages span multiple rows.
Also there's no copy/paste feature with a listview.

I use a listview for some of my logging in other apps too :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top