C# windows窗体应用程序中的记事本

C# windows窗体应用程序中的记事本,c#,winforms,C#,Winforms,我的字符串变量中有一些字符串。当我在Winform应用程序中单击“打开”按钮时,它会打开带有该字符串的记事本。应临时创建记事本。如果我关闭了记事本,它应该被永久删除 例如,当我单击“打开”按钮时,将生成字符串“结果”值,并且记事本应显示结果字符串值。这将演示如何打开记事本并将文本放入其中 这是一个启动记事本进程,然后向其中添加文本的简单示例。 将打开一个新的Notepad.exe进程,然后将文本“Sending a message,a message from me to you”添加到记事本的

我的字符串变量中有一些字符串。当我在Winform应用程序中单击“打开”按钮时,它会打开带有该字符串的记事本。应临时创建记事本。如果我关闭了记事本,它应该被永久删除


例如,当我单击“打开”按钮时,将生成字符串“结果”值,并且记事本应显示结果字符串值。

这将演示如何打开记事本并将文本放入其中

这是一个启动记事本进程,然后向其中添加文本的简单示例。 将打开一个新的Notepad.exe进程,然后将文本“Sending a message,a message from me to you”添加到记事本的文本区域

此处记录了SendMessage的常量0x000c。 该常量表示SETTEXT,这意味着如果使用该常量发送多条消息,记事本中的文本将被替换

来源:


我已经编辑了你的答案,包括你的博客中的直接引述,你从那里得到这个程序。如果这违背了您的意图,请随时回复。我觉得需要多解释一下。
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace SendMessageTest
{
    class Program
    {
        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("User32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);



        static void Main(string[] args)
        {
            DoSendMessage("Sending a message, a message from me to you");
        }



        private static void DoSendMessage(string message)
        {
            Process notepad = Process.Start(new ProcessStartInfo("notepad.exe"));
            notepad.WaitForInputIdle();

            if (notepad != null)
            {
                IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), "Edit", null);
                SendMessage(child, 0x000C, 0, message);
            }
        }
    }
}