Hello,
Here is the sample code for your requirement.
public partial class MyMsgBox : Form
{
public MyMsgBox(string msg)
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None ;
this.label1.Text = msg;
}
private void btnOk_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK ;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel ;
this.Close();
}
}
I have created a form with its FormBorderStyle set to FormBorderStyle.None. So when the form load, it doesn't have border. On the form, there is a lable which shows the message. Two buttons, one is Ok, another is Cancel. Before I close the form, I will set the DialogResult.
To use the MyMsgBox, below is the code.
MyMsgBox msgBox = new MyMsgBox("This is my MassageBox");
if (
msgBox.ShowDialog() == DialogResult.OK )
{
// Proceed forward steps
}
else
{
// Cancel
}
When user click Ok button, the msgBox's DialogResult is ok, you can Proceed forward steps. If the result is Cancel, then you can cancel the next step.
If I misunderstood something, please feel free to tell me.
Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the
All-In-One Code Framework!