When I close a window within the MES it puts the focus on the System Monitor

Someone on the forum who can help me:
My code works only when I am in Development mode.

private void StartProdForm_Closing(object sender, System.ComponentModel.CancelEventArgs args)
	{
		// Add Event Handler Code
	      var mesMainForm = Application.OpenForms["MESMenu"];
	
	      if (mesMainForm != null)
	      {
	          // Buscar el botón "System Monitor" en la ventana del MES
	          var systemMonitorButtons = mesMainForm.Controls.Find("epiButton1", true);
	
	          if (systemMonitorButtons.Length > 0)
	          {
	             // Tomar el primer botón encontrado y mandar el foco
	              var systemMonitorButton = systemMonitorButtons[0] as Control;
	              if (systemMonitorButton != null)
	              {
	                  System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
	                  timer.Interval = 600; // Intervalo de 100 ms
	                  timer.Tick += (s, e) =>
	                  {
	                      timer.Stop(); // Detener el timer después de ejecutar el código
	                      mesMainForm.Activate(); // Asegurarse de que la ventana del MES esté activa
	                      systemMonitorButton.Select(); // Mover el foco al botón 'System Monitor'
	                      systemMonitorButton.Focus(); // Mover el foco al botón 'System Monitor'
	 
	                  };
	                  timer.Start(); // Iniciar el timer
	              }
	          }
	      }
	      else MessageBox.Show("The main MES window was not found.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
	     
	}

What are you doing?

1 Like

When I exit any window, the System Monitor button must have focus, since I am implementing the use of HandHeld to capture Info, Example: JOB, Assembly, operation

1 Like

Handheld, you mean legacy hand held screens?

I mean, be able to read the information through HandHeld.
image
When exiting through the buttons marked in red, the focus should be on the System Monitor button in the main MES window.


That is the Hand Held we are using for this process
image

Heeeelp me?

Has anyone done this?