Hello. To Whome it may concern.
My following codes in c#, dose not work. Indeed method ShowBox's overloads in MyMessageBox Class do not return any value. can you help me to correct and why the reason is?
Best Regards
M. nouri
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace MN_Customized_MessageBox_14020230 { public partial class MyMessageBox : Form { static MyMessageBox newMessageBox; //public static string Button_id; public static DialogResult dialogResult;
public static DialogResult ShowBox(string txtMessage) { newMessageBox = new MyMessageBox(); newMessageBox.lblMessage.Text = txtMessage; newMessageBox.ShowDialog(); return dialogResult; }
public static DialogResult ShowBox(string txtMessage, string txtTitle) { newMessageBox = new MyMessageBox(); newMessageBox.lblMessage.Text = txtMessage; newMessageBox.Text = txtTitle; newMessageBox.ShowDialog(); return dialogResult; }
private void btnOk_Click(object sender, EventArgs e) { //Button_id = "1"; dialogResult = DialogResult.OK; newMessageBox.Dispose(); }
private void btnCancel_Click(object sender, EventArgs e) { //Button_id = "2"; dialogResult = DialogResult.Cancel; newMessageBox.Dispose(); } public MyMessageBox() { InitializeComponent(); } } } ---------------------------------------
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace MN_Customized_MessageBox_14020230 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { MyMessageBox.ShowBox("Do you want to exit?"); }
private void button2_Click(object sender, EventArgs e) { MyMessageBox.ShowBox("Do you want to exit?", "Exit"); }
private void button3_Click(object sender, EventArgs e) { //string btnClicked = MyMessageBox.ShowBox("Do you want to exit"); DialogResult d1 = DialogResult.Cancel; d1 = MyMessageBox.ShowBox("Do you want to exit?"); if (d1 == DialogResult.OK) { //User clicked OK button. Do some processing this.Close(); } else { //User clicked Cancel button. Do some processing. this.Close(); } } } }