首页 > 解决方案 > 如何移动其他应用程序但又不将它们重叠在一起

问题描述

我已经想出了如何移动多个窗口的方法,但是我遇到了一个问题,所有这些窗口都相互重叠,就像这样: 在此处输入图像描述 但我希望它是这样的: 在此处输入图像描述 我也尝试过做一个记事本实例,但我不能想不通

using System;
using System.Diagnostics;
using System.Windows.Forms;

using WindowScrape.Types;

namespace test
{
    public partial class Form1 : Form
    {
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        private void Form1_Load(object sender, EventArgs e)
        {

            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            uint SWP_NOSIZE = 0x0001;

            foreach (Process process in Process.GetProcessesByName("notepad"))
            {
                var lol = HwndObject.GetWindowByTitle(process.MainWindowTitle);

                var x = lol.Location.X;
                var y = lol.Location.Y;

                SetWindowPos(process.MainWindowHandle, 0, x + rnd.Next(0, 1), y + rnd.Next(0, 1), 0, 0, SWP_NOSIZE);
            }
        }
    }
}

标签: c#

解决方案


推荐阅读