Force MessageBox.Show to display on top
Solution 1:
When you show your MessageBox
set the TopMost
property on your main form to true
. The MessageBox
will be modal to the top most main form making the MessageBox
top most.
After the MessageBox
has been shown you can easily set the TopMost
property to false again.
private void button1_Click(object sender, EventArgs e)
{
this.TopMost = true; // Here.
DialogResult result1 = MessageBox.Show("Add some notes to your current ticket?",
"Add Notes",
MessageBoxButtons.YesNo);
this.TopMost = false; // And over here.
if (result1 == DialogResult.Yes) {
Timer tm;
tm = new Timer();
tm.Interval = int.Parse(textBox2.Text);
tm.Tick += new EventHandler(button1_Click);
string pastebuffer = DateTime.Now.ToString();
pastebuffer = "### Edited on " + pastebuffer + " by " + txtUsername.Text + " ###";
Clipboard.SetText(pastebuffer);
tm.Start();
}
else if (result1 == DialogResult.No)
{
// Do something else.
}
}
Solution 2:
try this MessageBoxOptions.ServiceNotification :
DialogResult res = MessageBox.Show(some text, "ATENCIÓN", MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1,
MessageBoxOptions.ServiceNotification);