我正在嘗試添加一個(gè)新的字典值并將一個(gè)新的用戶控件添加到流布局。但是按下添加控制按鈕會(huì)拋出一個(gè)帶有內(nèi)部異常的初始化程序異常,例如“Key has already been added”。我不知道完整的異常,因?yàn)槲液茈y找到如何打開(kāi)通常在 Visual Studio 中顯示的彈出錯(cuò)誤。已經(jīng)設(shè)置了一個(gè)循環(huán)來(lái)檢查鍵是否已經(jīng)添加到字典中,如果是則更改鍵(如代碼塊所示)。還嘗試清除流程布局控件列表。(沒(méi)有更改錯(cuò)誤)拋出錯(cuò)誤的函數(shù):/// <summary> /// Create a new key propertie set. /// </summary> /// <param name="sender"></param> /// <param name="e"></param>private void buttonAddKey_Click(object sender, EventArgs e){ // Create new UI key component in the flow layout. KeyPropertiesCtrl inputKeyCtrl = new KeyPropertiesCtrl(); flowLayoutKeys.Controls.Add(inputKeyCtrl); Console.WriteLine("inputKeyCtrl " + inputKeyCtrl.Name + " parent " + inputKeyCtrl.Parent.Name); // Create new data input key. CustomInputKey newKey = new CustomInputKey(); newKey.Activation.InputKey = new Interception(); Console.WriteLine("newKey " + newKey.Activation.InputKey); // Get a key binding from the user. try { Form1.Context = InterceptionDriver.CreateContext(); InterceptionDriver.SetFilter(Form1.Context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode.All); InterceptionDriver.SetFilter(Form1.Context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode.All); Form1.InterceptOnce(Form1.Context, out newKey.Activation.InputKey.DeviceId, out newKey.Activation.InputKey.TheStroke); }}所以我真正期望的是在按下按鈕控件之后。它在流布局中創(chuàng)建一個(gè)新的用戶控件,然后在它點(diǎn)擊函數(shù) InterceptOnce() 時(shí)凍結(jié)應(yīng)用程序,因?yàn)樗鼤?huì)在那里等待我按下輸入以綁定該輸入。最后存儲(chǔ)新的鍵綁定并將字典保存到文件中。但它在 while(Form1.CurrentSelections...){} 行拋出異常“key has already been added”,在我添加 while 循環(huán)和 try{} 之前,在 Form1.Context = InterceptionDriver 上拋出了異常。創(chuàng)建上下文();這很奇怪,因?yàn)槭褂?try{}catch(Exception excp){} 它不會(huì)拋出異常。我認(rèn)為異常與 new CustomInputKey(); 有關(guān) 并且不知道為什么......錯(cuò)誤: 截圖
1 回答

哈士奇WWW
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊
初始化程序錯(cuò)誤信息也顯示在 Class[Design] 中。當(dāng)拋出異常時(shí),使變量成為非靜態(tài)變量將移動(dòng),這有助于我找到異常的原因。
事實(shí)證明,我在控制組件的初始化階段為尚未創(chuàng)建的變量分配了一個(gè)值。
- 1 回答
- 0 關(guān)注
- 101 瀏覽
添加回答
舉報(bào)
0/150
提交
取消