?
Solved

How to add new line in a textBox

Posted on 2010-04-02
2
Medium Priority
?
480 Views
Last Modified: 2013-12-17
Hello Experts,
I am a complete beginner in C#. I am using the following "for loop" example to enter numbers in a textBox.  The example works fine except it displays the end of the loop in the box.
I need to have each digit displayed on a separate line.
Here is the code which is placed inside a button. The textBox1 property is set to multiline.

 

        private void button1_Click(object sender, EventArgs e)
        {
            for (int intCounter = 1; intCounter <= 100; intCounter++)
            {

                textBox1.Text = intCounter.ToString() + Environment.NewLine;

            }
0
Comment
Question by:a_anis3000
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 29496348
Change this line:

    textBox1.Text = intCounter.ToString() + Environment.NewLine;

To:

    textBox1.Text = textBox1.Text + intCounter.ToString() + Environment.NewLine;

Or:

    textBox1.AppendText(intCounter.ToString() + Environment.NewLine);
0
 

Author Comment

by:a_anis3000
ID: 29503723
Thanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
SingleRun is a tool that ensures that only one instance of an application is started, running it again brings the application to focus.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses
Course of the Month6 days, 4 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question