Событие срабатывает, когда я отлаживаю, но не когда запускаю его без C# [закрыто] ⇐ C#
-
Гость
Событие срабатывает, когда я отлаживаю, но не когда запускаю его без C# [закрыто]
I have a ComboBox with the SelectedIndexChanged Event Handler that is firing twice back-to-back while I'm debugging, but when I run it without debugging, it only fires once and it only does this because I trigger it directly. Otherwise, it fires once and not, respectively. Other than the processing waste, I wouldn't mind; however, I don't like having to trigger it manually.
The steps go like this: I have a couple KeyEvents monitoring when I press Shift+Enter. When I do, it adds ComboBox.Text to ComboBox.Items and sets ComboBox.DroppedDown to true.
private void IngredientEnter_KeyPressed(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ShiftKey) ShiftPressed = true; if (e.KeyCode == Keys.Enter) { if (ShiftPressed) { IngredientEnter.Items.Add(IngredientEnter.Text); IngredientEnter.DroppedDown = true; //I manually call the handler because it would call when I would debug, but not when I would just run it. IngredientEnter_SelectedIndexChanged(sender, EventArgs.Empty); } IngredientEnter.Text = ""; e.SuppressKeyPress = true; } } Again, when I'm debugging (if I remove the direct trigger), SelectedIndexChanged fires; when I'm running w/o debugging, it doesn't.
I am using Visual Studio 2022 so if this is the cause, how would I prevent this from happening. I sincerely apologize if this is a dup, but I looked forever and even created an account just to ask.
Edit: I have restructured the question, code, and details for clarity.
Источник: https://stackoverflow.com/questions/780 ... -o-c-sharp
I have a ComboBox with the SelectedIndexChanged Event Handler that is firing twice back-to-back while I'm debugging, but when I run it without debugging, it only fires once and it only does this because I trigger it directly. Otherwise, it fires once and not, respectively. Other than the processing waste, I wouldn't mind; however, I don't like having to trigger it manually.
The steps go like this: I have a couple KeyEvents monitoring when I press Shift+Enter. When I do, it adds ComboBox.Text to ComboBox.Items and sets ComboBox.DroppedDown to true.
private void IngredientEnter_KeyPressed(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ShiftKey) ShiftPressed = true; if (e.KeyCode == Keys.Enter) { if (ShiftPressed) { IngredientEnter.Items.Add(IngredientEnter.Text); IngredientEnter.DroppedDown = true; //I manually call the handler because it would call when I would debug, but not when I would just run it. IngredientEnter_SelectedIndexChanged(sender, EventArgs.Empty); } IngredientEnter.Text = ""; e.SuppressKeyPress = true; } } Again, when I'm debugging (if I remove the direct trigger), SelectedIndexChanged fires; when I'm running w/o debugging, it doesn't.
I am using Visual Studio 2022 so if this is the cause, how would I prevent this from happening. I sincerely apologize if this is a dup, but I looked forever and even created an account just to ask.
Edit: I have restructured the question, code, and details for clarity.
Источник: https://stackoverflow.com/questions/780 ... -o-c-sharp
Мобильная версия