Focus on open window

0

I have a wpf application with several buttons that open other windows off the main system.

I call them through:

.Show (); .Focus ();

If the user clicked on the button several times open, I fixed this by placing a global variable that opens when the window opens and closes.

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

    
asked by anonymous 03.03.2015 / 12:38

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 focus :

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 do not you declare util.Funcoes.is_open_window as bool ? It would make the code easier to read.

    
03.03.2015 / 15:36
0

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

    
03.03.2015 / 16:10