//调用Windows操作系统的 API函数
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0X0112;
public const int SC_MOVE = 0XF010;
public const int HTCAPTION = 0X0002;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text=="显示标题栏")
{
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.button1.Text = "关闭标题栏";
}
else
{
this.FormBorderStyle = FormBorderStyle.None;
this.button1.Text = "显示标题栏";
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//发送消息API函数
}