Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, February 14, 2012 10:00 AM
I have a timer running to check for the content of a file.
It works OK, only now if that file exist on a network there are a possibliity that the connection disappears. THus I would like to have a MessageBox to popup and inform that the file (or connection) is missing.
Now, if I do that the easy way ... the screen will be flooded with MessageBox'es since it will throw one each time the Timer fires.
There must be a way to check if the messageBox is already existing..
Something like:
if(MessageBox.show != true) MessageBox.show("File missing");
All replies (5)
Tuesday, February 14, 2012 10:40 AM âś…Answered
Hi,
you can use this code. Subscribe to the OnOkCilck event which will be called when user will click ok on message box. you can use Showed property to check if messagebox is all ready shown or not. To use this code call MyMessageBox.Show("Your message");
public static class MyMessageBox
{
public static bool Showed { get; set; }
public delegate void OnOK();
public static event OnOK OnOkClick;
public static void Show(string text)
{
System.Threading.ParameterizedThreadStart pT = new System.Threading.ParameterizedThreadStart(InvokeShow);
pT.BeginInvoke(text, null, null);
}
private static void InvokeShow(object text)
{
Showed = true;
if (MessageBox.Show(text.ToString()) == DialogResult.OK)
{
if (OnOkClick != null)
OnOkClick();
}
}
}
Bilhan silva
Tuesday, February 14, 2012 10:01 AM
skid,
why don`t you just disable the timer ?
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Tuesday, February 14, 2012 10:08 AM
Then if they re-plug the networkcable that fell out. They will have to restart the application.
It would more elegant if they could just press the ok button and re-check the connection, since the message will stay away if the connection is reestablished or other wise reappear.
Tuesday, February 14, 2012 11:02 AM
So you need to show the Messagebox modal.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Tuesday, February 14, 2012 11:06 AM | 2 votes
Declare a variable outside of all the methods, let's say: msgBoxIsDisplayed = false;
Then, first time you show it assign true to the varibale.
And before that, check (with if), if the variable is true or false.
If it is true, do not display the message box.
Don't forget to change the value back to false, when the messgae box is closed.
Noam B.
Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...