Windows 7 鼠标左键自动调整大小?

发布于 2024-10-20 08:44:59 字数 482 浏览 0 评论 0原文

我想知道 Windows 7 上有一个功能,当您的鼠标点击窗体左/右顶部时,它会自动将窗口大小调整为屏幕的一半。我正在尝试用我的 MDI 孩子做到这一点。这是我的代码,但是该功能不起作用。

private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        Form1 f1 = new Form1();
        if (e.X == f1.Width/2 - 30)
        {
            Form activeChild = this.ActiveMdiChild;
            activeChild.Width = this.Width / 2;
            activeChild.Height = this.Height;
            activeChild.Dock = DockStyle.Left;
        }
    }

I was wondering on windows 7 there is the function that when your mouse hits the form left/right top it will auto size the window to half the screen. I am trying to do that with my MDI Child. Here is the code that I have, however the function does not work.

private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        Form1 f1 = new Form1();
        if (e.X == f1.Width/2 - 30)
        {
            Form activeChild = this.ActiveMdiChild;
            activeChild.Width = this.Width / 2;
            activeChild.Height = this.Height;
            activeChild.Dock = DockStyle.Left;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-10-27 08:44:59

您可以尝试在实际子窗体的 Move 事件上执行此操作。在任何事件中,基于 Form1 的新实例处理事件都不会很好地工作。无论如何,这是一些在子进程内部查看的代码。 (丑陋,但它至少做了一些事情。)

    private void SubForm_Move(object sender, EventArgs e)
    {
        if (Location.X <= 0)
        {
            Width = MdiParent.Width / 2;
            Height = MdiParent.Height;
            Location = new Point(0,0);
            Dock = DockStyle.Left;
        }
    }

You might try doing that on the Move event of the actual child form. Handling the event based on a new instance of Form1 in any event won't work very well. Anyhow, here's some code as it would look inside the child. (Ugly, but it at least does something.)

    private void SubForm_Move(object sender, EventArgs e)
    {
        if (Location.X <= 0)
        {
            Width = MdiParent.Width / 2;
            Height = MdiParent.Height;
            Location = new Point(0,0);
            Dock = DockStyle.Left;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文