c#控制其他程序窗口位置

时间:2015-09-21 12:09:36   收藏:0   阅读:394
        //调用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是的窗体名称,包含路径

        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表示移动后的窗口是需要重画

      }

  

原文:http://www.cnblogs.com/mingl12/p/4825363.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!