bool ValidateOperation(string message) { var password = ""; if ((password = PasswordBox.ShowDialog(message)) == "") { return(false); } if (password != "123456") { MessageBox.Show("密码错误", "密码", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
private void Button2_Click(object sender, EventArgs e) { PasswordBox box = new PasswordBox(); box.Text = "密码"; box.Content = "请输入6位密码:"; box.ButtonDefaultCancelText = "取消"; box.ButtonCleanText = "清除"; box.ButtonOKText = "确认"; box.CheckFormat = (psw) => { if (psw.Length >= 6) { return(true); } return(false); }; box.ShowDialog(); }