废话不多说,直接上代码(talk is cheap,show me the code)
[DllImport("user32.dll")] //Namespace System.Runtime.InteropServices;
public static extern bool ReleaseCapture(); //release the mouse capture from a window in the current thread
//Send the specified message to a window,
//The SendMessage fuction calls the window procedure for the specified window and dose not return until the window procedure has processed the message
[DllImport("user32.dll")]
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MAXIMIZE = 0xF030;
public const int SC_RESTORE = 0xF120;
public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
private void btn_title_MouseDown(object sender, MouseEventArgs e)
{
if (e.Clicks == 2)
{
if (WindowState == FormWindowState.Maximized)
{
// Restore the form
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
}
else if (WindowState == FormWindowState.Normal)
{
//Maximize the form
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
}