我正在嘗試添加一個新的字典值并將一個新的用戶控件添加到流布局。但是按下添加控制按鈕會拋出一個帶有內部異常的初始化程序異常,例如“Key has already been added”。我不知道完整的異常,因為我很難找到如何打開通常在 Visual Studio 中顯示的彈出錯誤。已經設置了一個循環來檢查鍵是否已經添加到字典中,如果是則更改鍵(如代碼塊所示)。還嘗試清除流程布局控件列表。(沒有更改錯誤)拋出錯誤的函數:/// <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); }}所以我真正期望的是在按下按鈕控件之后。它在流布局中創建一個新的用戶控件,然后在它點擊函數 InterceptOnce() 時凍結應用程序,因為它會在那里等待我按下輸入以綁定該輸入。最后存儲新的鍵綁定并將字典保存到文件中。但它在 while(Form1.CurrentSelections...){} 行拋出異?!発ey has already been added”,在我添加 while 循環和 try{} 之前,在 Form1.Context = InterceptionDriver 上拋出了異常。創建上下文();這很奇怪,因為使用 try{}catch(Exception excp){} 它不會拋出異常。我認為異常與 new CustomInputKey(); 有關 并且不知道為什么......錯誤: 截圖
1 回答

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