简体   繁体   English

C#Windows窗体应用程序逐行读取文本框

[英]C# Windows Forms Application Read Textbox Line by Line

I want to make a program that has a multiline textbox, and the program will read it line by line. 我想制作一个具有多行文本框的程序,该程序将逐行读取它。
All I need is to get the line into a string, and after I'm finished with that line, it moves on. 我需要做的就是将这条线变成一个字符串,完成该行后,它就会继续前进。
How can I do that? 我怎样才能做到这一点?
Is there a built in function, like there is the getline() function in c++ and c? 是否有内置函数,例如c ++和c中的getline()函数?
Should I use a normal textbox or a richtextbox? 我应该使用普通文本框还是富文本框?

TextBoxBase.Lines property is what you're looking for. 您正在寻找TextBoxBase.Lines属性。

Per request, here's a sample: 根据请求,这是一个示例:

Code: 码:

namespace SomeApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // For each line in the rich text box...
            for (int i = 0; i < richTextBox.Lines.Length; i++)
            {
                // Show a message box with its contents.
                MessageBox.Show(richTextBox.Lines[i]);
            }
        }
    }
}

Result: 结果:

在此处输入图片说明
在此处输入图片说明在此处输入图片说明在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 C# Windows 窗体应用程序在列表框中指定正确的行 - Specify proper line in listBox using C# Windows Forms Application 如何在 windows forms c# 中画一条线? - How to draw a line in windows forms c#? c#如何逐行读取和写入多行文本框? - c# How to read and write from multiline textBox line by line? C# Windows 窗体应用程序 - 在文本框中显示 sql server 值 - C# Windows Forms Application - display sql server values in textbox 针对SQL DB的C#Windows窗体应用程序文本框验证 - C# Windows Forms Application textbox validation against SQL DB 运行时如何将命令行参数传递给C#Windows Forms应用程序 - How to pass a command line argument to a C# windows forms application while it is running C#Windows窗体应用程序:如何在不删除原始文件的情况下替换文本文件中的一行? - C# windows forms application:How can I replace a single line in a textfile without deleting the original file? 使用命令行参数从批处理文件运行Windows Forms Application(C#.NET 4.0) - Running Windows Forms Application (C# .NET 4.0) from batch file with Command Line Arguments C# - 是否可以创建一个可以从带命令行的命令行运行的Windows窗体应用程序? - C# - Is it possible to create a Windows Forms application that can run from the command line with parameters? 具有行号的Windows窗体文本框? - Windows Forms textbox that has line numbers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM