Solved

Implement a sliding window textbox

Posted on 2008-11-02
4
518 Views
Last Modified: 2008-11-03
Hi,
I am looking for the most efficient way to create a textbox to monitor comms data.

I need to limit it's size to 100 lines so when a new line arrives, it is added to the bottom and if the no. lines in the textbox >100 the first one is removed.

The behaviour would be similar to that of the hyperterminal window (cant see all data just latest x lines).

I need to do this in a highly performant manner.
Please advise on the best way to go about it. ps. not wedded to a text box so use another control if it suits.

(using visual studio 2005)

thanks.
Shaun
0
Comment
Question by:sdom100
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
alex_paven earned 450 total points
ID: 22863704
One way would be using a listbox, setting its datasource to a System.ComponentModel.BindingList<string> and working with the bindinglist; any changes you make in the list will be reflected in the control. If you need a textbox or similar control, you can inherit the bindinglist and provide a member that concatenates properly the list contents (100 is a relatively 'low' number for a stringbuilder, but calling it in a tight loop would indeed decrease performance). Other alternatives would include building a custom control that keeps track of changes in the list and paints the list as you see fit.
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 50 total points
ID: 22864247
My first thought was same as alex_paven's idea. I'd use a ListBox with the datasourse of the List<string> datatype. But I'd write my own class for this datasource List that would inherit from List<>. Basicly, I'd rewrite an Add() where I'd track number of lines and cleared items at the beginning of the list etc.
0
 

Author Comment

by:sdom100
ID: 22865261
My latest approach was to go with the listbox as suggested and simply use the add, check the items.count if >100 then use the RemoveAt function to take off the first line.
Which is most efficient ? (this way or using binding as per your suggestions) ?

Thanks,
Shaun
0
 
LVL 6

Expert Comment

by:alex_paven
ID: 22865270
Hard to say without testing, but I'd say the difference is minimal; the same mechanisms are used in both cases.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question