How to open Notepad from a Windows Forms application and place some text in it?

前端 未结 3 1933
抹茶落季
抹茶落季 2021-01-06 03:07

I\'m using VB.NET and Visual Studio 2008.

My question is: How do I open Notepad from a Windows Forms application, and then place some text string in the Notepad wind

3条回答
  •  难免孤独
    2021-01-06 03:17

    The easiest approach is to write a text-file, then open that, rather than the other way round.

    You can use System.File.IO.WriteAllText, and the System.Diagnostics.Process class.

    A quick code-sample would be along these lines:

    File.WriteAllText (
        @"C:\temp\myFile.txt", 
        "This is my letter header\nIt has a new-line in it")
    Process.Start("notepad.exe", @"C:\temp\myFile.txt");
    

提交回复
热议问题