调整窗口大小C# [英] Resize window size C#

查看:233
本文介绍了调整窗口大小C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从其他应用程序内调整运行的应用程序的窗口的大小?
我想,当我正在开工建设中的应用,其他应用程序(假设的iTunes)的宽度减少到其第2/3,使剩余1/3由我的应用程序占用。这两个应用程序应该是由用户完全可以访问和运行。
如果可能的话请帮忙。

Is it possible to resize a running application's window size from within another application? I want that when the application that I am building starts, another application (let's say itunes)'s width be reduced to its 2/3 so that the remaining 1/3 be occupied by my application. The two application should be running altogether and accessible by the user. Please help if possible.

推荐答案

您可以使用 SetWindowPos 调整大小另一个进程的窗口。

You can use SetWindowPos to resize another process's window.

    [DllImport("user32.dll")]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, 
        int x, int y, int width, int height, uint uFlags);

    private const uint SHOWWINDOW = 0x0040;

    private void resizeItunes()
    {
        System.Diagnostics.Process[] itunesProcesses = 
            System.Diagnostics.Process.GetProcessesByName("iTunes");

        if (itunesProcesses.Length > 0)
        {
            SetWindowPos(itunesProcesses[0].MainWindowHandle, this.Handle,
                0, 0, Screen.GetWorkingArea(this).Width * 2 / 3,
                Screen.GetWorkingArea(this).Height, SHOWWINDOW);
        }
    }

这篇关于调整窗口大小C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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