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();
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
}
C#无边框窗体的移动
最新推荐文章于 2025-12-30 09:43:34 发布
本文介绍了一个简单的C# Windows应用程序示例,演示如何实现窗体的鼠标拖动功能及关闭按钮的功能。通过调用.NET Framework提供的P/Invoke服务,该示例使用了user32.dll中的API函数ReleaseCapture()和SendMessage()来完成拖动操作,并实现了窗体的正常关闭。
450

被折叠的 条评论
为什么被折叠?



