1

このコードを使用して、メッセージボックスの特定の回答のフォームを閉じようとしています。に属していYesないというエラーが表示され続けます。私は基本的にこのコードをMSサイトから直接コピーしたので、何が問題なのかわかりません。ヘルプ?NoDialogResult::

private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
             if(!watchdog->Checked)
             {
                 if((MessageBox::Show("CAN Watchdog is currently OFF. If you exit with these settings, the SENSOWheel will still be engaged. To prevent this, please enable CAN Watchdog before closing. Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == DialogResult::No))
                 {
                     return;
                 }
                 else
                 {
                     close_Click(this, e);
                 }
             }

     }
4

3 に答える 3

1
if((MessageBox :: Show( "..."、 "Watchdog Warning"、MessageBoxButtons :: YesNo、MessageBoxIcon :: Question)==
    System :: Windows :: Forms :: DialogResult :: No))                  
{{
   e->キャンセル=true; //閉じない              
}                  
于 2011-06-14T13:04:48.420 に答える
0

DialogResult列挙型とのDialogResultプロパティの間には名前の衝突がありますForm。前者が必要な場合、コンパイラは後者を参照していると想定します。

あいまいさを解決する1つの方法は、列挙型への参照を完全に修飾することです。

if((MessageBox::Show("CAN Watchdog ... Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::No))

このスレッドで2番目のメソッドを見つけました; using namespace System...ステートメントをブロックの外に移動してnamespaceから、グローバル名前空間を介して列挙型を参照します。

if((MessageBox::Show("CAN Watchdog ... Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == ::DialogResult::No))
于 2011-06-14T13:11:04.217 に答える
0

これは、全体像を確認できるようにいくつかの追加コードを含む実用的なソリューションです。この例では、BackgroundWorkerアプリを閉じる前に停止する必要のある作業がいくつかあります。

#pragma region Start/Stop/Exit

    private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^  sender, System::ComponentModel::RunWorkerCompletedEventArgs^  e) {
                 if(e->Cancelled)     
                 {
                     rtbLog->Text = rtbLog->Text  +  ">>> Application stopped \n";  
                 }
                 else   
                 {
                     rtbLog->Text = rtbLog->Text  +  ">>> Application completed \n";  
                 }
             }

    private: System::Void startToolStripMenuItemStart_Click(System::Object^  sender, System::EventArgs^  e) 
             {
                 if (backgroundWorker1->IsBusy == false) 
                 { 
                     backgroundWorker1->RunWorkerAsync(1);  //starting background worker
                 }
             }

    private: System::Void stopToolStripMenuItemStop_Click(System::Object^  sender, System::EventArgs^  e) 
             {
                 if (backgroundWorker1->IsBusy == true && backgroundWorker1->WorkerSupportsCancellation == true) 
                 {     
                     backgroundWorker1->CancelAsync(); 
                 } 
             }    

    private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {

                 if((MessageBox::Show("Would you still like to quit?", "Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == 
                     System::Windows::Forms::DialogResult::No))                  
                 {
                     e->Cancel = true;    // Don't close and BackgroundWoker is executing.             
                 }  
                 else
                 {
                     if (backgroundWorker1->IsBusy == true && backgroundWorker1->WorkerSupportsCancellation == true) 
                     {     
                         backgroundWorker1->CancelAsync(); 
                     } 
                 } 
             }

    private: System::Void exitToolStripMenuItemExit_Click(System::Object^  sender, System::EventArgs^  e) {

                 Application::Exit(); // The user wants to exit the application. Close everything down.

             }

#pragma endregion
于 2015-11-12T13:19:05.937 に答える