Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am displaying a message box on timer which displays a message box after every 1 minute, the problem is if user does not clicks on "OK" , and timer is still running then multiple message boxes get opened which I don't want..

Please help me to display only one message box and next will be displayed only if user clicks on oK button, timer should not be disabled..


please help.
Posted

Create a custom message box and call it when timer ticks. Destroy it when user clicks OK. If user doesn't click OK, check for the messagebox object in the next timerTick event and if it exists, do not open a new message box.

Hope this solves your problem..!!!
 
Share this answer
 
Dear DjRocks,

This is the logic part, if you prompt messages while timer is running , it will prompt you for each and every intervel.

So my suggession is

Before prompting the message, check for existing message result,

DialogResult result1 = MessageBox.Show("Is Clicked?",
		"Mybox",
		MessageBoxButtons.YesNo);
}


// before prompting message

C#
if(result1==DialogResult.yes)
{
   // Go ahead
}


This is only the idea,and will helpfull to you

Thanks,
SP
 
Share this answer
 
Hi,
For this you need to check if the messagebox is running or not for this
Set up a CBT hooks Then you'll get notification of all created, activated, deactivated and destroyed windows. Then use GetWindowClass to check if the hWnd created/activated is in fact a MessageBox.
 
Share this answer
 
Hi =) You must look to WinApi methods FindWindow and method EndDialog.

you can use this class for your purpose:

C#
public static class NativeMethods
{
    private const string c_user32 = "user32.dll";

    static NativeMethods() { }

    #region user32 p/invoke
    [DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern IntPtr FindWindow(string className, string windowName);

    [DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern bool CloseWindow(IntPtr hWnd);

    [DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern bool DestroyWindow(IntPtr hWnd);

    [DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern bool BringWindowToTop(IntPtr hWnd);

    [DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern IntPtr SetFocus(IntPtr hWnd);

    [DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
    internal static extern bool EndDialog(IntPtr hDlg, IntPtr nResult);
    #endregion

    public static void CloseDialog(string windowName, bool bringToTop = false)
    {
        IntPtr hWd = default(IntPtr);
        hWd = FindWindow(null, windowName);
        if (hWd != default(IntPtr))
        {
            EndDialog(hWd, IntPtr.Zero);
        }
    }
}


To close you MessageBox call such construction:
C#
NativeMethods.CloseDialog("Information")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900