How to open text in Notepad from .NET?

前端 未结 4 1954
太阳男子
太阳男子 2020-12-08 20:38

When I click a button on a Windows Forms form, I would like to open a Notepad window containing the text from a TextBox control on the form.

How can I do that?

4条回答
  •  天命终不由人
    2020-12-08 21:14

    Save the file to disk using File.WriteAllText:

    File.WriteAllText("path to text file", myTextBox.Text);
    

    Then use Process.Start to open it in notepad:

    Process.Start("path to notepad.exe", "path to text file");
    

提交回复
热议问题