Mình tạo 2 form. 1 form chính và 1 form dùng để làm messageBox custom.
trên messageBox custom có 1 textbox cho người dùng nhập key vào, key này dùng để kiểm tra khi thoát, nếu key đúng thì cho thoát chương trình, key sai thì k được thoát.
public hhddkk()
{
InitializeComponent();
}
static hhddkk redmix;
static DialogResult result = DialogResult.No;
public static DialogResult Show()
{
redmix = new hhddkk();
string str = redmix.textBox1.Text;
str = str.Trim();
str = str.ToLower();
redmix.ShowDialog();
if (str == "i love you")
{
return DialogResult.OK;
}
else
{
return DialogResult.No;
}
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Lỳ à, cho treo máy tiếp, ahihi ", "Thông báo");
}
code trên là của messageBox của mình và các sự kiện click.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = false;
DialogResult result = hhddkk.Show();
if (result == DialogResult.No)
{
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
Code trên là sự kiện lúc đúng form chính của mình. Không biết lỗi sao mà nó k hoạt động giống ý muốn
Ai rành c# help em vớiPreformatted text