1
I created a window JanelaUm
, every time I click on button
this window is displayed.
in the code-behind
of JanelaUm
have the event window_KeyDown
with the following code:
if (e.Key == Key.Escape)
this.Close();
But if the user clicks 5 times on button
to display the JanelaUm
, when closing using the button esc
will close all five windows, not just one.
Would anyone have an idea of how to close only one? and the other 4 remain open?
How you create and do display of windows?
– ramaral
JanelaUm JUm = new JanelaUm(); JUm.ShowDialog();
– MeuChapeu
In that
form
, you don’t have a button that makes a cancel?– Pablo Tondolo de Vargas
No, just the button itself
form
.– MeuChapeu
i couldn’t reproduce the problem, if you can, post more code from your example, use git to upload the project if possible.
– Pablo Tondolo de Vargas
I don’t see how you can open 5 windows if you’re using
ShowDialog()
? When opening the first phocus stays in it and you can no longer access the initial window until you close the one that was opened.– ramaral
Yeah, I made a mistake
Show();
– MeuChapeu
The @Lucasmotta response, solved the problem, is closing only the active window, the others remain open.
– MeuChapeu
I find that strange because only the active window should receive the key. Just out of curiosity, where(Event) is that you are testing the key?
– ramaral
and at the event
private void window_KeyDown(object sender, KeyEventArgs e)
– MeuChapeu