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

**URL:** <https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210>\
**Category:** Kinetic ERP\
**Tags:** customization\
**Created:** [October 23, 2024, 7:43pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210 "2024-10-23T19:43:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MEMFabila](https://www.epiusers.help/user_avatar/www.epiusers.help/memfabila/32/69670_2.png) [@MEMFabila](https://www.epiusers.help/u/MEMFabila)\
**Post date:** [October 23, 2024, 7:43pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210/1 "2024-10-23T19:43:19Z")

</div>

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

```cs
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);
	     
	}

```

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [October 23, 2024, 10:00pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210/2 "2024-10-23T22:00:19Z")

</div>

What are you doing?

---

<div class="post-metadata">

**Author:** ![MEMFabila](https://www.epiusers.help/user_avatar/www.epiusers.help/memfabila/32/69670_2.png) [@MEMFabila](https://www.epiusers.help/u/MEMFabila)\
**Post date:** [October 23, 2024, 10:49pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210/3 "2024-10-23T22:49:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hally](https://www.epiusers.help/user_avatar/www.epiusers.help/hally/32/1263_2.png) [@Hally](https://www.epiusers.help/u/Hally)\
**Post date:** [October 24, 2024, 2:02pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210/4 "2024-10-24T14:02:52Z")

</div>

Handheld, you mean legacy hand held screens?

---

<div class="post-metadata">

**Author:** ![MEMFabila](https://www.epiusers.help/user_avatar/www.epiusers.help/memfabila/32/69670_2.png) [@MEMFabila](https://www.epiusers.help/u/MEMFabila)\
**Post date:** [October 24, 2024, 2:31pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210/5 "2024-10-24T14:31:43Z")

</div>

I mean, be able to read the information through HandHeld.  
 ![image](https://www.epiusers.help/uploads/default/original/3X/b/a/ba6178029dc7c56847dda278d6bb90489d4e7db8.png)  
When exiting through the buttons marked in red, the focus should be on the System Monitor button in the main MES window.

 ![image](https://www.epiusers.help/uploads/default/original/3X/9/7/97fe6335a30018ac4f0ef0d0800344458e17648e.png)  
That is the Hand Held we are using for this process  
 ![image](https://www.epiusers.help/uploads/default/original/3X/1/0/10aee89a5c5922012045715200c38a191f791afc.jpeg)

---

<div class="post-metadata">

**Author:** ![MEMFabila](https://www.epiusers.help/user_avatar/www.epiusers.help/memfabila/32/69670_2.png) [@MEMFabila](https://www.epiusers.help/u/MEMFabila)\
**Post date:** [October 28, 2024, 4:52pm UTC](https://www.epiusers.help/t/when-i-close-a-window-within-the-mes-it-puts-the-focus-on-the-system-monitor/120210/6 "2024-10-28T16:52:42Z")

</div>

Heeeelp me?

Has anyone done this?
