如何在 Panel 移动窗体窗口内进行鼠标拖动? [英] How do I make mousedrag inside Panel move form window?

查看:20
本文介绍了如何在 Panel 移动窗体窗口内进行鼠标拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 System.Windows.Forms.Panel,我想启用它,以便在用户单击并拖动鼠标时将窗口拖动到周围.

I have this System.Windows.Forms.Panel that I want to enable so that if the user click and drags the mouse drags the window around to.

我可以这样做吗?我是否必须实现多个事件?

Can I do this? Do i have to implement multiple events?

推荐答案

可以通过面板的MouseMove事件来实现

You can achieve it by using the MouseMove Event of the panel

示例应该是这样的(抱歉没有测试过)

Example should be something like this (Sorry have not tested it)

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        this.Location = new Point(Cursor.Position.X + e.X , Cursor.Position.Y + e.Y);
    }
}

这篇关于如何在 Panel 移动窗体窗口内进行鼠标拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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