473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

New Line in Text Box

Hi,
I have a method which displays 'Hello'. Every time I call the method, it needs to display 'Hello' in a new line of the text box. I'm not able to do that. I only get one 'Hello' which happens to be the third called method's result. How can I get 'Hello' 3 times, in different lines in the text box when I call my method 3 times.
Example:

Expand|Select|Wrap|Line Numbers
  1. myMethod("Hello", 5==5);
  2. myMethod("Hello", 5==5);
  3. myMethod("Hello", 5==5);
  4.  
  5. private void myMethod(string p, bool p_2)
  6. {
  7.   textBox1.Text = (p + p_2);
  8. }
  9.  
Thank You,
Regards..
Jul 14 '11 #1
2 2361
GaryTexmo
1,501 Expert 1GB
There's a couple things you need to do...

For starters, you're always assigning to the Text property of your textbox with a new value. This is going to overwrite it every time it's called. What you need to do is add to the textbox.

Expand|Select|Wrap|Line Numbers
  1. myTextBox.Text += "Text to append";
Now, you also need to set your textbox to a multiline textbox. To do this, set it's Multiline property to true (either in the designer or in code).

Finally, when you append your text, you need to put a line separator between your lines. The easiest way to do this is to insert an Environment.Newline before you append to your textbox. For example...

Expand|Select|Wrap|Line Numbers
  1. public void AppendTextToTextBox(TextBox theTb, string text)
  2. {
  3.   if (theTb != null)
  4.   {
  5.     if (theTb.Text != "") theTb.Text += Environment.NewLine;
  6.     theTb.Text += text;
  7.   }
  8. }
Or something to that effect.
Jul 15 '11 #2
Thank you Gary! That was helpful in getting things working.
Jul 16 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Wade Leftwich | last post by:
Every couple of months I have a use for the experimental 'scanner' object in the re module, and when I do, as I did this morning, it's really handy. So if anyone is counting votes for making it a...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
3
by: Jow Blow | last post by:
I am trying to make a word wrap type function for a multi line text box field that will be saved to a text file. The word wrap property looks good in the app but when saved to a text file the line...
1
by: Mike L | last post by:
This is for a Win form. I am able to send a string to my multi line text box, but I want the string to have hard returns in it. Here is my code for the string. string s =...
3
by: Kieran Breen | last post by:
Hiya, I was just wondering if anyone knows how to impose a maximum length on a muti line text box in asp.net. There is a parameter for this but even when its set it dosent seem to make any...
9
by: C.K | last post by:
Can I enter a two-line text description on a button, chr(13) doesn't seem to do anything ?
1
by: amruta | last post by:
I need to write something like this in the multi line text box dynamically as the value is obtained. how can i do it example: abce 1232 qwert asdfg qwqw ghdjhfj ...
8
by: MLH | last post by:
Am trying to import 20,000+ lines of text in a file FTP'd from a UNIX platform to windows via FTP session in a DOS box. About 2000 records have multiple lines in them separated by CRLF's. ...
8
by: cj | last post by:
I use multi-line text boxes with vertical scroll bars in several of my programs to display log information as the programs run. Once the text more than fills the visible portion of the textbox I...
2
by: shihab | last post by:
I have created two text boxes,One is single line text box other is multiline. On button click i want to 'add text from single text box to Multiline text box'one by one. please give solution for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.