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

c#拖动无边框窗体(调用API)

2012-11-13 17:28 423 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 拖动无边框窗体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.MouseDown += new MouseEventHandler(DragNoFrameWindow_MouseDown);
}

[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwdn, int wMsg, int mParam, int lParam);//向指定的窗体发送windows消息

[DllImport("user32.dll")]
public static extern bool ReleaseCapture();//释放当前线程中某个窗口捕获的光标

public const int WM_SYSCOMMAND = 0x0112;//该变量表示向windows发送的消息类型
public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加信息
public const int HTCAPTION = 0x0002;//该变量用来表示发送信息的附加信息

private void DragNoFrameWindow_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: