Hi every body
i devoloped a custom MessageBox Class to use it in other application, and i made the application
and it work fine except in one place and it's Window_Closing handler.
If i replce the custom MessageBox with the standard MessageBox it works when i use my custom message box it doesn't and i don't know why and here's asnapshot of my code
[code]
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
and i made the application which will use it
and it work fine except in one place and it's Window_Closing handler, here's a snapshot of my code
Code:
# private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
# {
#
# if (savingRequest == true)
# {
# //The problem is here in the statement below
# switch (MessageBoxCustomized.Show("Save Changes", "Attention", MessageBoxButton.YesNoCancel))
# {
# case MessageBoxResult.Yes:
# {
# notifyIcon.Dispose();
# SaveTreeView();
# }
# break;
#
# case MessageBoxResult.No: notifyIcon.Dispose();
# break;
#
# case MessageBoxResult.Cancel:e.Cancel = true;
#
# break;
#
# }
# }
If i replce the custom MessageBox with the standard windows MessageBox object it works fine as i want but when i use my custom message box object the compiler skip all the code from the statement
i had stepped my code as u suggested and i made a break at the Fn
public static MessageBoxResult Show(string msg, string title, MessageBoxButton butsta)
if i made butsta=YesNo then every thing is fine and it work,but if i made butsta=YesNoCancel the step work fine untill reach the statement
msgBox.ShowDialog();
it execute it but doesn't show the dialog and immediately go to the next statement
return _msgboxresult; //the default value for _msgboxresult is None
Hey guys
i'm fraud about the problem by canceling window closing event handler and created a new fun called Terminate and created a custom command "Exit" and call the Terminate fun from within it
/// <summary>
/// Fn to confirm the user if data saving required befor closing the application
/// </summary>
private void Terminate(/*System.ComponentModel.CancelEventArgs ee*/)
{
if (savingRequest == true)
switch (MessageBoxCustomized.Show("Do you want to save changes", "Saving Attention", MessageBoxButton.YesNoCancel))
{
case MessageBoxResult.Yes:
notifyIcon.Dispose();
SaveTreeView();
Application.Current.Shutdown();
break;
case MessageBoxResult.No:
notifyIcon.Dispose();
Application.Current.Shutdown();
break;
case MessageBoxResult.Cancel:
// ee.Cancel = true;
break;
}
else //if no saving required
{
switch (MessageBoxCustomized.Show("Are you Sure to exit ?", "Exit Application", MessageBoxButton.YesNo))
{
case MessageBoxResult.Yes: Application.Current.Shutdown(); break;
case MessageBoxResult.No: break;
}
}
}
and it works perfect but i want to know why "The MessgeBoxCustomized window doesn't work only in window closing event handler" is there any technical problem!
Hey people i have found the answer why "The MessgeBoxCustomized window doesn't work only in window closing event handler" in stackoverflow forum and here's the context literal
"The Closing event cannot be canceled if you call Application.Current.Shutdown(). Just call the Window.Close() method instead, which will give you a chance to veto the close operation. Once all your program's windows have closed the application will shutdown automatically."
and i was using Application.Current.Shutdown() to exit my application and when i used mainWnd.Close(); since my main window name is "mainWnd" then every thing is working fine thanks for all of you
Bookmarks