0

在窗口应用程序中,我使用 c# 创建了一个表单并将可见的错误最小化、最大化按钮和表单边框设置为无,我在表单顶部放置了一个面板,在该面板中我放置了关闭、最小化按钮。现在我如何拖动窗口窗体。请有任何参考。我的代码是

        this.ControlBox = false;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.FormBorderStyle = FormBorderStyle.None;

谢谢你。

4

1 回答 1

0

只需为您的MouseDown,MouseMoveMoueUp事件注册Panel

    bool MouseDownFlag = false;
    Point start = new Point(0, 0);

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        start = new Point(e.X, e.Y);
        MouseDownFlag = true;
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (MouseDownFlag)
        {
            Point newPoint = new Point();
            newPoint.X = this.Location.X - (start.X - e.X);
            newPoint.Y = this.Location.Y - (start.Y - e.Y);

            this.Location = newPoint;
        }
    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        MouseDownFlag = false;
    }
于 2012-10-30T06:57:19.383 回答