2013-08-20 31 views
0

我正在使用C++編寫一個小項目並將其打包到GUI中。參考源代碼是enter link description here(下載源代碼 - 61.1 Kb)C#WinForms中的提示對話框

我想在選擇「菜單」 - 「編輯」 - 「參數設置」時提示一個對話窗口。我已經得出一個對話框,這樣

enter image description here

時,單擊「參數設置」

private void menuItem7_Click(object sender, EventArgs e) 
{ 
    if (drawArea.GraphicsList.ShowFormParameter(this)) 
    { 
     drawArea.SetDirty(); 
     drawArea.Refresh(); 
    } 
} 


public bool ShowFormParameter(IWin32Window parent) 
{ 
    return true; 
} 

但它不工作時,對話框不顯示,當點擊。我怎麼能意識到這一點?

+0

了嚴重問題在這裏...你正在談論創建一個MFC應用程序,您已經標記了問題[tag:C++]和[tag:mfc],但是您顯示的代碼顯然是C#並且使用了WinForms框架。更糟的是,問題上有一個[tag:c#]標記。所以我不知道你實際上想做什麼。 MFC不適用於C#。 MFC部分只是一個紅鯡魚?你真的只是在創建一個C#WinForms應用程序嗎? –

回答

4

您發佈的任何代碼都沒有顯示對話框。您使用ShowDialog成員函數來完成該操作,但是您沒有調用該函數。

從上下文中,我不知道ShowFormParameter函數的目的是什麼。我想這是試圖通過將代碼顯示在單個函數中的參數對話框來模塊化代碼。

在任何情況下,你需要寫這個函數裏面的代碼實際上顯示您所創建的對話框:

public bool ShowFormParameter(IWin32Window parent) 
{ 
    // This creates (and automatically disposes of) a new instance of your dialog. 
    // NOTE: ParameterDialog should be the name of your form class. 
    using (ParameterDialog dlg = new ParameterDialog()) 
    { 
     // Call the ShowDialog member function to display the dialog. 
     if (dlg.ShowDialog(parent) == DialogResult.OK) 
     { 
      // If the user clicked OK when closing the dialog, we want to 
      // save its settings and update the display. 
      // 
      // You need to write code here to save the settings. 
      // It appears the caller (menuItem7_Click) is updating the display. 
      ... 

      return true;    
     } 
    } 
    return false; // the user canceled the dialog, so don't save anything 
} 
+0

它的工作原理!非常感謝你!我會繼續學習:) –

+0

還有一個想知道的想提高,雖然它與主題沒什麼關係。參考源代碼演示了一個繪圖工具。因此,如果我在繪圖區域繪製矩形,可以從代碼中提取形狀參數(例如DrawRectangle.cs中的x,y,寬度和高度),然後顯示在新的對話框中? –

+0

@qingyao使用「Ask Question」按鈕提出一個新問題。確保在你的新問題中包含你正在談論的代碼。 –