How can I implement custom dialog result for the following code, what all the changes I need to make in the following code to get the dialog result?
private void addButton(enumMessageButton MessageButton)
{
switch (MessageButton)
{
case enumMessageButton.OK:
{
//If type of enumButton is OK then we add OK button only.
Button btnOk = new Button(); //Create object of Button.
btnOk.Text = "OK"; //Here we set text of Button.
btnOk.DialogResult = DialogResult.OK; //Set DialogResult property of button.
btnOk.FlatStyle = FlatStyle.Popup; //Set flat appearence of button.
btnOk.FlatAppearance.BorderSize = 0;
btnOk.SetBounds(pnlShowMessage.ClientSize.Width - 80, 5, 75, 25); // Set bounds of button.
pnlShowMessage.Controls.Add(btnOk); //Finally Add button control on panel.
}
break;
case enumMessageButton.OKCancel:
{
Button btnOk = new Button();
btnOk.Text = "OK";
btnOk.DialogResult = DialogResult.OK;
btnOk.FlatStyle = FlatStyle.Popup;
btnOk.FlatAppearance.BorderSize = 0;
btnOk.SetBounds((pnlShowMessage.ClientSize.Width - 70), 5, 65, 25);
pnlShowMessage.Controls.Add(btnOk);
Button btnCancel = new Button();
btnCancel.Text = "Cancel";
btnCancel.DialogResult = DialogResult.Cancel;
btnCancel.FlatStyle = FlatStyle.Popup;
btnCancel.FlatAppearance.BorderSize = 0;
btnCancel.SetBounds((pnlShowMessage.ClientSize.Width - (btnOk.ClientSize.Width + 5 + 80)), 5, 75, 25);
pnlShowMessage.Controls.Add(btnCancel);
}
break;
}
}
internal static void ShowBox(string messageText, string messageTitle, enumMessageIcon messageIcon, enumMessageButton messageButton)
{
frmShowMessage frmMessage = new frmShowMessage();
frmMessage.setMessage(messageText);
frmMessage.Text = messageTitle;
frmMessage.addIconImage(messageIcon);
frmMessage.addButton(messageButton);
frmMessage.ShowDialog();
}
Main.cs
frmShowMessage.ShowBox("This is message box which represent message with title, custome button and custom icon.", "This is message title", enumMessageIcon.Question, enumMessageButton.OKCancel);
Now how do further I implement code to get dialog result?
Instead of
try this