2016-11-24 17 views
0

끝내기 옵션이있는 메뉴와 창 닫기를 통해 응용 프로그램을 닫고 싶습니다. 그리고 둘 다 프롬프트 메시지를 추가했습니다. 내가 System.Windows.Application.Current.Shutdown(); 후 종료 후 프롬프트 메시지를 두 번 때문에 Exit_Click 이벤트에 제공이라고하면 는하지만 ShellWindow_Closing 당신은 Exit 버튼을 누를 때마다종료 메뉴 및 종료 이벤트를 통해 C# 종료 응용 프로그램

public partial class SWindow : Window 
{ 
    public SWindow() 
    { 
      this.Closing += ShellWindow_Closing; 
    } 

    private void ShellWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
    { 
     if (MessageBox.Show("Any running migration task will be aborted. \nAre you sure you want to exit the application ?", 
      "Exit Proventeq Migration Acclerator", 
      MessageBoxButton.YesNo, 
      MessageBoxImage.Question) == MessageBoxResult.No) 
      e.Cancel = true; 
    } 
} 

private void Exit_Click(object sender, RoutedEventArgs e) 
{ 
    if (MessageBox.Show("Any running migration task will be aborted. \nAre you sure you want to exit the application ?", "Exit Proventeq Migration Acclerator", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) 
     e.Handled = true; 
} 
+1

질문의 형식을 지정하십시오. – FCin

+0

[X 버튼을 클릭했을 때 확인 메시지 요청] (0120-998-301) –

+0

종료 메뉴에서 처리기 집합 e.Handled = true, 그럼 다른 처리기를 호출해서는 안됩니다 – adminSoftDK

답변

0

로 이동 또는 당신은 ALT + F4하여 응용 프로그램을 닫거나 오른쪽까지 X (cross)를 누르면됩니다 , 그것은 항상 귀하의 애플 리케이션 폐쇄에옵니다.

간편한 방법은 BtnMenuExit_Click을 앱 폐쇄로 처리하는 것입니다. 그런 다음 다른 동작 - Window에 대한 이벤트가 메시지 상자의 결과에 따라 취소됩니다.

public partial class SWindow : Window 
{ 
    public SWindow() 
    { 
     this.Closing += ShellWindow_Closing; 
    } 

    private void ShellWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
    { 
     if (MessageBox.Show("Any running migration task will be aborted.\nAre you sure you want to exit the application ?", "Exit Proventeq Migration Acclerator", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) 
     { 
      e.Cancel = true; 
     } 
    } 

    private void BtnMenuExit_Click(object sender, EventArgs e) 
    { 
     this.Close(); 
    } 
} 

//designer part 
public partial class SWindow 
{ 
    //other code 
    private void InitializeComponent() 
    { 
     Button BtnMenuExit = new Button(); 
     BtnMenuExit.Click += new EventHandler(BtnMenuExit_Click); 
     //other styles etc.. 
    } 
    //other code 
} 
+1

Ctrl-F4는 응용 프로그램을 닫지 않으며, MDI 응용 프로그램의 MDI-Child 양식 만 닫을 수 있습니다. 필요한 응용 프로그램을 닫으려면 Alt-F4 – GuidoG

+0

감사합니다. 필자는 잘못 입력했습니다. – Tatranskymedved