c#怎样实现下面生成的txt中的内容自动换行???

string hebe = @"C:\pathlog.txt";
File.AppendAllText(hebe, comboBox2.Text );

pathlog.txt中的内容总紧凑在一起,怎样实现第二次写入时另起一行写入呢???

在TextBox中实现换行的方法如下:

(1)在Visual Studio中添加一个“Windows 窗体应用程序”项目

(2)在Form上添加2个TextBox和1个Button

设置textBox1的属性

    Multiline = True

    ScrollBars = Both

(3)Form1窗体代码Form1.cs

using System;
using System.Windows.Forms;

namespace BaiduWinformApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            button1.Text = "输入";
        }
        
        // 点击button1 “输入”按钮
        private void button1_Click(object sender, EventArgs e)
        {
            // 取出textBox2中的内容,去除前后的空格
            string line = textBox2.Text.Trim();
            
            // 如果输入的内容为空,则退出
            if (string.IsNullOrEmpty(line)) return;
            
            // 在textBox1中显示输入内容
            // 注意!使用 Environment.NewLine 实现换行
            textBox1.AppendText(line + Environment.NewLine);
            
            // 准备再次输入
            textBox1.Text = string.Empty;
        }
    }
}

(4)运行效果

温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-12-14
string hebe = @"C:\pathlog.txt";
File.AppendAllText(hebe, comboBox2.Text+"\r\n" );本回答被提问者采纳
第2个回答  2008-12-14
/n...你试试看,我记不太清楚了
相似回答