在C#中将数据从文本框导出到记事本 [英] exporting data from textbox to notepad in C#

查看:61
本文介绍了在C#中将数据从文本框导出到记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中将数据从文本框导出到记事本?

how to export data from textbox to notepad in C#?

推荐答案

这应该有帮助,



http://www.dotnetperls.com/streamwriter [ ^ ]
This should help,

http://www.dotnetperls.com/streamwriter[^]


Code Credit Here: http://stackoverflow.com/questions/7613576/how-to-open-text-in-notepad-from-net #answer-14295249 [ ^ ]



他们回答的代码:



使用



Code Credit Here: http://stackoverflow.com/questions/7613576/how-to-open-text-in-notepad-from-net#answer-14295249[^]

Code from their answer:

usings

using System.Runtime.InteropServices;





code





code

public static class NotepadHelper
    {
        [DllImport("user32.dll", EntryPoint = "SetWindowText")]
        private static extern int SetWindowText(IntPtr hWnd, string text);

        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

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

        public static void ShowMessage(string message = null, string title = null)
        {
            Process notepad = Process.Start(new ProcessStartInfo("notepad.exe"));
            notepad.WaitForInputIdle();

            if (!string.IsNullOrEmpty(title))
                SetWindowText(notepad.MainWindowHandle, title);

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







用法





usage

NotepadHelper.ShowMessage(textbox1.Text, textbox2.Text);


这篇关于在C#中将数据从文本框导出到记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆