【问题标题】:How to save an entry in a text box in Visual Studio | C#如何在 Visual Studio 的文本框中保存条目 | C#
【发布时间】:2017-07-26 18:26:37
【问题描述】:

我理解为富文本框,例如在打开的文件对话框控件中,

richTextBox1.LoadFile(openFileDialog1.FileName.RichTextBoxStreamType.PlainText)

我理解为在控制台中使用 WriteLine,例如,

File.WriteAllText(path, variable)

但我不确定如何使用除richTextBox 之外的其他东西来编写文本文件,例如文本框或标签。我尝试使用 textBox1 代替 richTextBox1 但这似乎不正确。

【问题讨论】:

标签: c# visual-studio savefiledialog


【解决方案1】:
File.WriteAllText(path, textBox1.Text);

【讨论】:

    【解决方案2】:

    您必须先从文本框中提取文本。

    textbox1.Text //this gets you the text in the textbox
    

    【讨论】:

    • TextBox的Text属性定义为字符串,无需调用ToString将字符串转为字符串。
    • @BlakeThingstad 好收获
    猜你喜欢
    • 2014-04-10
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多