Focus on open window

Asked

Viewed 1,001 times

0

I am with an application in wpf, with several buttons that open other windows outside the main system.

I call them through the:

.show(); Focus.();

If the user clicks multiple times the button opens multiple windows, I fixed this by placing a global variable that arrow when the window opens and closes.

The problem is that I need to focus on the window already open when the user clicks again on the button, because the window is already open, along with the main.

  • How about doing the disable button after this is clicked and have opened the new window successfully?

  • I can’t do that, my task is to focus on the open window, but I can’t.

  • How many windows of the same type can you have open? From what I understand each button opens a type of window, right?.

  • Yes each button opens a different window, what I need to do is bring in front of all the window that was requested on the button, understand?

  • I’m not sure I understand. Because, if each button opens only one type of window and there can be only one window of each type open, just, by clicking again on the button, do janela.setFocus(). If you post some code it would be easier to help!

  • Usuario_Consultar frmGo = new Usuario_Consultar();

 if (util.Funcoes.is_open_window != 1)
 {
 util.Funcoes.is_open_window = 1;
 frmGo.Show();
 frmGo.Focus();
 }

  • This is the button pressing function, when it presses there is an instance of the window object that is declared. Then there is an if that asks if the global variable that controls the windows was set so there is no more than one window, entering if it opens the window and gives the focus to it.

Show 3 more comments

2 answers

0


If I understand util.Funcoes.is_open_window == 1 indicates that the window is open. So add a else to your condition and make the window receive the phocus:

Usuario_Consultar frmGo = new Usuario_Consultar();
if (util.Funcoes.is_open_window != 1) //Abre a janela
{ 
    util.Funcoes.is_open_window = 1; 
    frmGo.Show(); 
    frmGo.Focus(); 
}
else //A janela está aberta recebe o focus
{
    frmGo.Activate();
}

Why don’t you declare util.Funcoes.is_open_window as bool? It would make the code easier to read.

  • I tried it but I don’t know why it doesn’t focus, it doesn’t do anything understood?

  • I was instantiating the object again when I pressed the button, just put it as global and set it as null.

  • I was considering that frmGois global. That Usuario_Consultar frmGo = new Usuario_Consultar(); was outside the button click method

  • Thanks ramaral, I put as your answer the correct.

0

I was instantiating the object again when I pressed the button, just put it as global and set it as null and when instantiative it looked different from null, so just ask if it was different from null to focus it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.