replica aero form-shake / borderless form / panel

时间:2017-07-31 13:04:58

标签: c# .net winforms

在面板或无边框窗口中实现'windows aero form-shake'功能的最简单方法是什么?

例如。我有一个无边框的形式,看起来像这样

image 我有一个类,其中包含一些处理MouseDown,MouseMove和MouseUp的代码。如果需要,我可以将其包含在编辑中(但是此代码还处理屏幕捕捉和各种其他无边界所需事件,因此它很长/很复杂。)

这里的目标是创建这个静态类,以便它有3个事件MouseDown,MouseMove和MouseUp。你只需将任何Panel的MouseDown,MosueMove和MouseUp事件绑定到类中存储的这三个方法,这将启用拖动,捕捉和更改窗口状态(这三个我已经实现) - 还可以添加一个窗口航空风格方法

这是一个简化版本:

    public static void MouseDown(MouseEventArgs now) {
        if (!Dragging) {
            Dragging = true;
            Location = new Point(now.X, now.Y);
        }
    }
    public static void MouseMove(Form form, MouseEventArgs now) {
        TargetForm = form;
        if (Dragging) {
           ... <more code>
           IsDocked = false;
           TargetForm.Location = new Point(Cursor.Position.X - (TargetForm.Width / 2), Cursor.Position.Y);
        }
        Point CurrentLocation = new Point();
        CurrentLocation = TargetForm.PointToScreen(now.Location);
        TargetForm.Location = new Point(CurrentLocation.X - Location.X, CurrentLocation.Y - Location.Y);
           ... <more code>
        }
    }
     public static void MouseUp(MouseEventArgs now) {
        if (Dragging) {
            Dragging = false;
            ... <more code>
       }
     }

我希望增加“摇动”表单的能力。我可以通过实现另一种表单类型来做到这一点,但这并不理想。我不确定如何将其实现到我现有的代码中。

0 个答案:

没有答案