c# 运行其他程序并调整位置和大小
时间: 2024-02-23 07:00:45 浏览: 27
你可以使用C#中的Process类来运行其他程序,并使用Shell命令来调整它们的位置和大小。下面是一个简单的示例代码:
```
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace ProcessDemo
{
class Program
{
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static void Main(string[] args)
{
Process.Start("notepad.exe"); //运行notepad
//等待notepad启动
System.Threading.Thread.Sleep(1000);
//找到notepad的窗口句柄
IntPtr hWnd = Process.GetProcessesByName("notepad")[0].MainWindowHandle;
//调整notepad的位置和大小
SetWindowPos(hWnd, IntPtr.Zero, 100, 100, 500, 500, 0x0040);
}
}
}
```
在上面的代码中,使用Process.Start方法来启动notepad。然后等待一秒让notepad启动完全,并使用Process.GetProcessesByName方法找到notepad的窗口句柄。最后使用SetWindowPos方法来调整notepad的位置和大小。