2

Hy,

In my c# application i want to make a box were i can put text in line by line to display information about what the application is currently doing. I tried to look on the Internet because this is a very common way of interfacing with users, and im sure there are lots of samples out there. The problem is, i don't know how i should call this kind of textbox.

I hope it's clear to you guys what im looking for!

EDIT 1

I want a box like the one in this installer.

image
(source: softpedia-static.com)

5
  • You can have a panel and show and hide it, or even better create an about form with and showdialog.
    – kostas ch.
    Jun 26, 2013 at 13:30
  • 1
    Can you post some code?
    – michele
    Jun 26, 2013 at 13:32
  • probably a multiline textbox that you AppendText() to Jun 26, 2013 at 13:32
  • You could use a textbox and then make it read only and uneditable. You'd just append the line TextBox1.text += "More text" + " \r\n"; Jun 26, 2013 at 13:33
  • possible duplicate: stackoverflow.com/questions/2196097/… Jun 26, 2013 at 13:33

4 Answers 4

7

You could use a multiline textbox and then make it read only and uneditable. You'd just append the line and add carriage returns (\r\n)

      TextBox1.text += "More text" + " \r\n";
4
  • I'm a c++ guy so I'm not sure about it, but I doubt its going to automatically scroll to the last line just by adding text. Might also have to check if the scrollbar has been moved by the user, so it doesn't autoscroll down if the user wants to read something.
    – Edward A
    Jun 26, 2013 at 13:39
  • That should do the trick! @Edward Just checked it and it scrolled down automatically. About the user reading something im not to worried with this application, because after every 10 lines it needs user interaction, so they would have plenty of time to scroll up if they want to. Jun 26, 2013 at 13:44
  • 1
    Thanks for this Amit, Sometimes you are thinking of a very difficult solution for a problem, when there is actually a very easy one available! Jun 26, 2013 at 13:48
  • That's what we tend to do as programmers, overcomplicate things. But 9 out of 10 times there's a quick, and easy solution to the problem at hand. Good Luck with your program! Jun 26, 2013 at 13:59
2

AmitApollo's answer is perfect.

If you are worried about the look of the box, try setting those properties:

  • Font: if you want the console to look like the DOS console, try using a fixed width font like Consolas, or Courier New.
  • BackColor: set it to a gray color to have a box that looks like the one in your image

Also, if you want to add new logs to the beginning of the box, use

txtConsole.text = "Log's text" + " \r\n" + txtConsole.text;

If you want the box to scroll to the last line when a new one is added, check this post

1

I will give you some tips in which you can go ahead and research, I will not give you an answer that provides the fully working code of your project:

  1. Create the UI
  2. It will be a multiline textbox
  3. Set the progress bar to progress with what the code is doing
  4. Set a loop to show what the progress bar is going by

I will warn you this is relatively difficult, so you will need to research this further.

Many people assume the progress bar will automatically show the progress, this is not true. You can go two ways, put a timer onto the progress bar, or set it up to update on each line of code your work goes through. I hope you will now start to see how this may prove difficult to create within your code. But remember, Difficult is not impossible enjoy learning!

1
  • Thank you for your post! Luckily enough for me the progress bar is not too difficult in my application. (I already have this part working). This is because the application is going to retrieve information from an external PCB over a serial connection. So i just have to update it on every received line using this code: progressBar1.PerformStep(); However, I can see how it might be a pain in the ass to do this when you have a different kind of application. Jun 26, 2013 at 14:11
1

Just starting to use Windows Froms. I always used console apps, but wanted to see if I could make my GeneticAlgorithm look better. So I crumbled across this question.

Found out that using AppendText(string text) is a bit better and faster way to add new lines to the textBox. Also, it auto scrolls and you can use Thread.Sleep with no problems.

Just wanted to add this to the discussion. :)

2
  • Hi Csaba, thanks for pitching in! This is the right answer in the OP's situation. especially for only appending text. TextBoxBase implementes .Text similarly to a StringBuilder and so doesn't reallocate every time you append. .AppendText() can make a meaningful difference in responsiveness especially if the messages are coming in fast. If anyone is interested, The Mono implementation of TextBox is here for anyone interested: github.com/mono/mono/blob/main/mcs/class/System.Windows.Forms/… . Jun 6, 2022 at 18:15
  • Just as a style note I would recommend putting backticks around code items in your text, it makes them pop and read as code. Also, it's best if you can both provide an example of what you're talking about in a code block, and if you can reduce the amount of non-informative information in your post. The idea is to present the answers to the question in the most effective way possible, and extraneous information distracts from that . You can find more information at the help center, here: stackoverflow.com/help. See you! Jun 6, 2022 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.