您的位置:首页 > 编程语言 > C#

C#使用_鼠标拖动无标题栏窗口

2008-12-08 20:43 351 查看
今天晚上在论坛看到牛人回复了,受教不少

用鼠标控制无标题栏Form的移动,以前只知道通过注册MouseDown,MouseMove和MouseUp事件来实现,而使用下面的方法更加简单

来源(http://topic.csdn.net/u/20081208/19/f5d92437-4602-4798-b8d1-0d6730dec98f.html?seed=1470908657

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace WindowsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

[DllImport("user32.dll", EntryPoint = "SendMessage")]

public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);

[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]

public static extern int ReleaseCapture();

public const int WM_SysCommand = 0x0112;

public const int SC_MOVE = 0xF012;

private void Form1_MouseDown(object sender, MouseEventArgs e)

{

ReleaseCapture();

SendMessage(this.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);

}

private void Form1_Load(object sender, EventArgs e)

{

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: