推荐文章

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符
C#监控程序启动和关闭

C#监控程序启动和关闭

C#监控程序启动和关闭using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;using System.Threading;namespace ProcessListener{ class Program { static void Main(stri
C#操作USB口的摄像头

C#操作USB口的摄像头

private const uint BM_CLICK = 0xF5; 鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++ [DllImpt("user32.dll", EntryPoint = "SendMessage", SetLastErr = true, Set = Set.Auto)]private static extern int SendMe
C# FTP操作

C# FTP操作

C# FTP操作
C#文件监控对象FileSystemWatcher

C#文件监控对象FileSystemWatcher

使用C#文件监控对象FileSystemWatcher对文件夹下的删除、修改、新增

.NET平台自带的 Process 和 SendKeys控制外部程序

日期:2018-08-15 点击:1831 来源:PB2.CN
用 C# 的Winform程序,.NET平台自带的 Process 和 SendKeys控制记事本程序程序,在指定路径创建文本文件,写入内容并保存。




private void button1_Click( object sender, EventArgs e )
  {
      //启动notepad.exe 记事本程序,并在d:\下创建 或 打开 text.txt文件
      System.Diagnostics.Process txt = System.Diagnostics.Process.Start ( @"notepad.exe", @"d:\text.txt" );
      txt.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
      //等待一秒,以便目标程序notepad.exe输入状态就绪
      txt.WaitForInputIdle ( 1000 );
      //如果目标程序 notepad.exe 没有停止响应,则继续
      if ( txt.Responding )
      {
        //开始写入内容
        SendKeys.SendWait ( "-----下面的内容是外部程序自动写入-----\r\n" );
        SendKeys.SendWait ("写入内容");     //写入内容
        SendKeys.SendWait ( "{Enter}{Enter}" );     //写入2个回车
        SendKeys.SendWait ( "文档创建时间:" );
        SendKeys.SendWait ( "{F5}" );          //发送F5按键
        SendKeys.SendWait ("{Enter}");       //发送回车键
        SendKeys.SendWait ( "^s" );       //发送 Ctrl + s 键
        SendKeys.SendWait ( "%{F4}" );      // 发送 Alt + F4 键
        MessageBox.Show ("文件已经保存成功!");
      }
  }


这篇文档对您是否有帮助?

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符
C#监控程序启动和关闭

C#监控程序启动和关闭

C#监控程序启动和关闭using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;using System.Threading;namespace ProcessListener{ class Program { static void Main(stri
C#操作USB口的摄像头

C#操作USB口的摄像头

private const uint BM_CLICK = 0xF5; 鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++ [DllImpt("user32.dll", EntryPoint = "SendMessage", SetLastErr = true, Set = Set.Auto)]private static extern int SendMe
C# FTP操作

C# FTP操作

C# FTP操作
C#文件监控对象FileSystemWatcher

C#文件监控对象FileSystemWatcher

使用C#文件监控对象FileSystemWatcher对文件夹下的删除、修改、新增