Status in a Window's program.

U

UJ

I have a Windows program where I has messages that are displayed to the user
of what is going on. What's the best way to do this? Currently I'm using a
text box and limiting it to 500 lines and it seems to get slow especially
once I get to 500 lines.

Plus I'd like to put the messages at the end and have whatever is doing it
scroll the end so the user sees the most recent message.

TIA - Jeff.
 
S

Steve Barnett

You could always use a list box and add your new status items to the end. If
you make the newly added item the current item, it scrolls in to view. Also,
because you're not refreshing the whole control every time, it should be a
lot quicker.

If you want to limit to 500 items, you'll need to check how many items there
are in the list box and delete one from the top each time you add the 501st
to the bottom.

HTH
Steve
 
U

UJ

How do I select the last item I entered. I can figure out what it is - it
would be TreeView.Items.Count - but I don't see any selectItem or some such
item.
 
S

Steve Barnett

If you add a standard list box to a form, you will see that it has a
"SelectedIndex" property. Set that to Items.Count -1. For example;

lbStatus.Items.Add("This is a status message");
lbStatus.Items.Add("This is another status message");
lbStatus.Items.Add("This is yet another status message");

lbStatus.SelectedIndex = lbStatus.Items.Count -1;
lbStatus.Refresh();

That'll select and scroll to the last item in the list box (Note; NOT a
listview or a TreeView).

If you want to limit the status messages to, say, 500 messages, occasionally
invoke a function that includes a routine to prune the list. This'll do
something like this:

while (lbStatus.Items.Count > 500)
lbStatus.Items.Remove(lbStatus.Items[0]);

This removes items from the top of the list box until there are only 500
left. I would suggest you only call this occasionally in order to reduce the
overhead of pruning the list. Alternatively you could, of course, check the
size of the list every time you add a new message.

Steve
 

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