Add lines to textBox.

  • Thread starter Thread starter PawelR
  • Start date Start date
P

PawelR

Hello Group,
I have very simple question. In my application I have textBox (tbInfo) where
tbInfo.Multiline = true;
How simple add lines to this component? Sametime I need add first, sametime
last line.

PawelR
 
To insert a line at the start of the textbox:
TextBox.SelectionStart = 0;
TextBox.SelectedText = <text to insert> + Environment.NewLine;

To add to the last line, use TextBox.AppendText() method.

HTH.

Hello Group,
I have very simple question. In my application I have textBox (tbInfo) where
tbInfo.Multiline = true;
How simple add lines to this component? Sametime I need add first, sametime
last line.

PawelR
 
You can also use a StringWriter:

StringBuilder sb = new StringBuilder(TextBox.Text);
StringWriter sw = new StringWriter(sb);

sw.WriteLi ne(NewText);

TextBox.Text = sw.ToString();

it is a little easier to use and can be faster if you are concatentating a
lot.
If you are just doing it a couple of times, then the overhead to initialize
the classes may not be worth it.
 

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

Similar Threads


Back
Top