c# - 用鼠标拖动无边框窗体

标签 c# winforms drag

<分区>

Possible Duplicate:
C# - Make a borderless form movable?

我在 C# 中制作了一个无边框的表单,通过设置

this.FormBorderStyle = FormBorderStyle.None;

现在,问题是如何用鼠标拖动它?

最佳答案

这应该是您要找的"Enhanced: Drag and move WinForms"

public partial class MyDraggableForm : Form
{
    private const int WM_NCHITTEST = 0x84;
    private const int HTCLIENT = 0x1;
    private const int HTCAPTION = 0x2;

    ///
    /// Handling the window messages
    ///
    protected override void WndProc(ref Message message)
    {
        base.WndProc(ref message);

        if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
            message.Result = (IntPtr)HTCAPTION;
    }
    public MyDraggableForm()
    {
        InitializeComponent();
    }
}

正如博文所述,这是一种“愚弄”系统的方法。这样您就无需考虑鼠标上/下事件。

关于c# - 用鼠标拖动无边框窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4767831/

相关文章:

c# - 有没有办法要求提供给方法的参数不为空?

javascript - ActiveX 在 IE 11 中不工作

c# - 枚举/迭代 System.Windows.Forms.DataGrid 的行

javascript - 使用javascript和css拖动

c# - 当给出开始点、结束点、速度和移动开始时间时,有没有更简单的方法来计算 2D 中的对象当前坐标?

c# - 从 XML 转换数组

c# - 遍历大量记录

c# - WPF WinForms 多层混合嵌套

javascript - 使用 d3 拖动行为的原点为树节点创建 "drag handle"

iphone - 在touchesMoved方法中检测[UITouch view]