c# - Form still closing when I choose no -


i have following code

private void form1_formclosing(object sender, formclosingeventargs e) {     if (cmd.cetaktanya("are sure want exit ?"))     {         cmd.cetaksukses("thank using " + cmd.title);         starturl();     } }  public bool cetaktanya(string message) {     bool status = false;      dialogresult dialogresult = messagebox.show(message, title, messageboxbuttons.yesno, messageboxicon.exclamation);     if (dialogresult == dialogresult.yes)     {         status = true;     }     else if (dialogresult == dialogresult.no)     {         status = false;     }     return status; } 

why form still closed though choose "no" @ confirmation dialog?

use cancel property cancel event if "no" clicked.

private void form1_formclosing(object sender, formclosingeventargs e) {     if (cmd.cetaktanya("are sure want exit ?"))     {         cmd.cetaksukses("thank using " + cmd.title);         starturl();     }     else         e.cancel = true; } 

additionally, method refactored bit more compact:

public bool cetaktanya(string message) {     var result = messagebox.show(message, title, messageboxbuttons.yesno, messageboxicon.exclamation);     return result == dialogresult.yes; } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -