2015-04-02 51 views
-1

我在編程世界很新,我有一些問題。我將不勝感激任何幫助!!沒有超載匹配委託'System.EventHandler'/'System.Windows.Forms.FormClosedEventHandler'

我有一個窗體「FW_Details」,它在從treeView2(8個節點)中選擇一個節點並打開一個按鈕後打開。我想在窗體打開時顯示先前插入的數據,讓用戶修改它,並在關閉時保存已修改的數據(針對每個特定節點)。

呼叫FW_Details從主窗體形成:

 foreach (TreeNode node in treeView2.Nodes) 
     { 
      if (node.IsSelected) 
      { 
       FW_Details fw = new FW_Details(node.Name); 
       fw.Show(); 
      } 

FW_Details包含此:

public partial class FW_Details : Form 
{ 
    public FW_Details(string name) 
    { 
     switch (name) 
     { 
      case "x": 
       FW_Details_Load(null, null, "x");     
       break; 
      case "y": 
       FW_Details_Load(null, null, "y"); 
       break; 

事件:FW_Details_Load

private void FW_Details_Load(object sender, EventArgs e, string mycase) 
    { 
     switch (mycase) 
     { 
      case "x": 
       Quellpfad.Text = Properties.Settings.Default.Quellpfad; 
       Zielpfad.Text = Properties.Settings.Default.Zielpfad; 
       Schlüsselwort.Text = Properties.Settings.Default.Schlüsselwort; 
       DateiTyp.Text = Properties.Settings.Default.DateiTyp; 
       Suchzeit.Text = Properties.Settings.Default.Suchzeit.ToString(); 
       break; 
      case "y": 
       Quellpfad.Text = Properties.Settings.Default.Quellpfad; 
       Zielpfad.Text = Properties.Settings.Default.Zielpfad; 
       Schlüsselwort.Text = Properties.Settings.Default.Schlüsselwort; 
       DateiTyp.Text = Properties.Settings.Default.DateiTyp; 
       Suchzeit.Text = Properties.Settings.Default.Suchzeit.ToString(); 
       break; 

事件:FW_Details_FormClosed

private void FW_Details_FormClosed(object sender, FormClosedEventArgs e, string mycase) 
    { 

     switch (mycase) 
     { 
      case "x": 
       Properties.Settings.Default.Quellpfad = Quellpfad.Text; 
       Properties.Settings.Default.Zielpfad = Zielpfad.Text; 
       Properties.Settings.Default.Schlüsselwort = Schlüsselwort.Text; 
       Properties.Settings.Default.DateiTyp = DateiTyp.Text; 
       Properties.Settings.Default.Suchzeit = Convert.ToInt32(Suchzeit.Text); 
       Properties.Settings.Default.Save(); 
       break; 

Q1:我收到2錯誤信息:

Error 1. No overload for 'FW_Details_FormClosed' matches delegate 'System.Windows.Forms.FormClosedEventHandler'

Error 2 No overload for 'FW_Details_Load' matches delegate 'System.EventHandler'

是不是因爲我加了該事件的paramaeter 「字符串mycase」?我怎麼解決這個問題? Q2302。 FW_Details表單載入數據後出現在屏幕上..我希望用戶能夠修改 表單中的參數,然後保存爲每個節點指定的參數......我該怎麼做?我應該在show..but後在主窗體中調用事件FW_Details_FormClosed,但它不被識別

+3

不能添加'串myCase '在你的窗體關閉事件中。而不是使全局變量,然後訪問它 – Rohit 2015-04-02 12:24:17

回答

0

您不能將參數添加到事件處理程序自我委託。您必須遵守事件定義的代表簽名。

這意味着,private void FW_Details_Load(object sender, EventArgs e, string mycase)應該成爲private void FW_Details_Load(object sender, EventArgs e)

你可能想使mycase類變量,這樣你就可以在事件處理中訪問:

public partial class FW_Details : Form 
{ 
    private string mycase; 

    ... 
} 
+0

謝謝你的答案!我真的不知道如何將事件將被要求案件x或y .. – 2015-04-03 17:33:10

+0

對不起。我不明白你的問題。 – 2015-04-03 20:48:39

相關問題