|
-
December 5th, 2009, 04:00 PM
#1
Very basic question concerning text boxes...
Well thanks to you all's help on my last post, my first C# program is almost completed. I'm working on the final touches right now. The last thing I'm doing is adding a log to my program. I've made a multi-line text box and I wish to output a sort of log to it as the program operate (like a status bar except multiline). I know you can set what's in the text box by saying something like txtLog.Text = "some text here" but since it's going to be continuously updated, is there a simple way to just add on to what already exists in the text box? Thanks again for all your help!
-
December 5th, 2009, 06:33 PM
#2
Re: Very basic question concerning text boxes...
I woudl probably use a RichTextBox with ReadOnly set to true. You may want to set the background color back to 'Window' afterward. You can then use the AppendText method to add lines to the text box.
-
December 5th, 2009, 06:52 PM
#3
Re: Very basic question concerning text boxes...
txtLog.Text += "new text";
-
December 5th, 2009, 07:02 PM
#4
Re: Very basic question concerning text boxes...
The AppendText method is nice because you do not have add your own newlines.
-
December 5th, 2009, 07:35 PM
#5
Another TextBox Question.
I have another question about textboxes which maybe I can slip in here ...
In a RichTextBox is it possible to use right-to-left selectively. That is, can I have some lines right to left, and others left to right?
And, of course, if so ... how?
-
December 5th, 2009, 07:55 PM
#6
Re: Another TextBox Question.
I believe, you can't and I suggest that you use a label to output logs, as it is neater. also about the addition to that, you can do
txtLog.Text += System.Enviroment.NewLine + "Your text here";
that will add a new line to the text box or whatever you got, and then add your text to the new line 
Hope this helps,
ClayC
-
December 5th, 2009, 08:02 PM
#7
Re: Very basic question concerning text boxes...
Keep in mind that the following approach may not be very performant for long logging sessions:
Code:
txtLog.Text += "\nnew text";
This is because the += operator is going to have to copy the existing text out of the control, append to it and then copy it back. Each time this happens an entire new string is created.
So the larger the log history becomes, the more noticeable the delay is going to be when each entry is logged.
-
December 7th, 2009, 03:22 AM
#8
Re: Another TextBox Question.
 Originally Posted by ClayC
I believe, you can't and I suggest that you use a label to output logs, as it is neater. also about the addition to that, you can do
txtLog.Text += System.Enviroment.NewLine + "Your text here";
that will add a new line to the text box or whatever you got, and then add your text to the new line
Hope this helps,
ClayC
I don't agree. While it would not be hard to switch over, using a RichTextBox gives you formatting options that a label does not. Labels should only be use for the most simple of text operations. Also, RichTextBox offers the AppendText( ) method which suggests that it may use a StringBuilder or some sort of growing buffer internally to avoid the performance issues that Arjay pointed out.
-
December 8th, 2009, 03:35 PM
#9
Re: Very basic question concerning text boxes...
Arjay gave the proper answer, but I would suggest you to look at the DataGridView. You can make a log window similar to visual studio (like the Error List). By using a BindingList with the DataSource of the DGV, it becomes quite easy to do some operations (sorting, filtering (ie errors/messages), etc) and display it the way you like. And it's fast.
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
|