1.点击回车登陆
private void textBox2_KeyDown(object sender, KeyEventArgs e) //点击回车就登陆
{
if (e.KeyData == Keys.Enter)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
button1_Click(null,null );
}
}
} //这个事件是密码框的keydown事件
2.拖动无边框的窗体
private Point mPoint = new Point(); //可以拖动
private void userlogin_MouseDown(object sender, MouseEventArgs e)
{
mPoint.X = e.X;
mPoint.Y = e.Y;
}
private void userlogin_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = MousePosition;
myPosittion.Offset(-mPoint.X, -mPoint.Y);
Location = myPosittion;
}
} //窗体的两个mouse事件
3.点击X按钮退出程序
protected override void WndProc(ref Message msg) //判断程序的退出时点击的X还是操作影响
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE))
{
// 点击winform右上关闭按钮
// 加入想要的逻辑处理
// DialogResult dr = MessageBox.Show("确认关闭程序", "提示", MessageBoxButtons.YesNo);
// if (dr.Equals(DialogResult.Yes))
// {
// Application.Exit();
// }
Application.Exit();
}
base.WndProc(ref msg);
}
4.控件随着窗体的大小改变而改变
设置为fill,然后在控件sizechanged事件中设置子空间的宽和高和父窗口的宽和高一直。