九溪

溪水润知林,滴露启慧心

用户工具

站点工具


wiki:csharp:winform-czyd-qt-cxck

操作移动其他程序窗口

moveotherform.cs
public class A
{	
	//调用Win32 API
	[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "MoveWindow")]
	public static extern bool MoveWindow(System.IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
 
	//打开窗体方法,fileName是C++的窗体名称,包含路径	
	private void OpenAndSetWindow(String fileName)
	{
		Process p = new Process();//新建进程
		p.StartInfo.FileName = fileName;//设置进程名字
		p.StartInfo.CreateNoWindow = true;
		p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
		p.Start();
		MoveWindow(p.MainWindowHandle, 200, 300, 500, 400, true);
		//p.MainWindowHandle是你要移动的窗口的句柄;200,300是移动后窗口左上角的横纵坐标;500,400是移动后窗口的宽度和高度;true表示移动后的窗口是需要重画	
    }
}

评论

请输入您的评论. 可以使用维基语法:
 
wiki/csharp/winform-czyd-qt-cxck.txt · 最后更改: 2023/01/03 15:25 由 127.0.0.1