using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WinFormLoginUI { /// <summary> /// WinForm制作相对美观的登录窗体 /// LDH @ 2021-3-22 /// </summary> public partial class FrmLogin : Form { public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; public FrmLogin() { InitializeComponent(); } [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); /// <summary> /// 窗体的MouseDown事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmMain_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } private void picExit_Click(object sender, EventArgs e) { Environment.Exit(0); } private void picMinimum_Click(object sender, EventArgs e) { WindowState = FormWindowState.Minimized; } private void FrmLogin_Load(object sender, EventArgs e) { SetWatermarks(); MouseDown += FrmMain_MouseDown; } /// <summary> /// Set Watermarks /// </summary> private void SetWatermarks() { txtAccount.SetWatermark("Please input your account."); txtPwd.SetWatermark("Please input your password."); } private void MyMouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } } private void btnReset_Click(object sender, EventArgs e) { txtAccount.ResetAndFocus(); txtPwd.Clear(); } } }