Hi all, I am working on an application for work and I need a customized messagebox to appear. I have created a simple form called Alert.cs that I have styled the way I want and added one button with a click method of this.Close(). now I want it to behave exactly like a standard messagebox.show(). I have the form showing but when I use the standard messagebox.show("text of alert") it waits to continue operation until the user click 'OK', this is what I want the form to do.
+5
A:
Use Form.ShowDialog();
. This allows the form to act the same way as a MessageBox
in the sense that it retains focus until closed.
Kyle Rozendo
2010-03-01 06:14:58
AWESOME! Exactly what I was looking for. Thanks a lot!
jakesankey
2010-03-01 06:20:54
My pleasure. Remember to mark as accepted if it helped you! Thanks :)
Kyle Rozendo
2010-03-01 06:23:10
Just like to add. You can also set the DialogResult property of the form to match that of a message box.
Jojo Sardez
2010-03-01 07:08:46
+2
A:
You can use a modal windows form. Something like
Form frm = new Form();
frm.ShowDialog(this);
Shows the form as a modal dialog box with the currently active window set as its owner.
rahul
2010-03-01 06:15:34
A:
You don't write how you currently display your Alert Form, but calling
alert.ShowDialog();
instead of alert.Show()
should do the trick.
The ShowDialog that takes an owner is an even better alternative:
alert.ShowDialog(owner);
Mark Seemann
2010-03-01 06:15:43
+1
A:
You will need to implement a static method for your Alert class if you want the exact MessageBox-like behaviour.
public static DialogResult Show(string text)
{
Alert form = new Alert(text);
return form.ShowDialog();
}
Now you can use the form by calling:
Alert.Show("my message");
kor_
2010-03-01 07:05:07