Created
April 25, 2025 13:59
-
-
Save pedroinfo/437955225b9d75c8fb88b3e7a52d4e5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Diagnostics; | |
| using System.Runtime.InteropServices; | |
| using System.Threading; | |
| public static class WindowHelper | |
| { | |
| [DllImport("user32.dll")] | |
| private static extern bool SetForegroundWindow(IntPtr hWnd); | |
| /// <summary> | |
| /// Tenta abrir uma pasta no Explorer e trazê-la para frente. | |
| /// </summary> | |
| /// <param name="path">Caminho da pasta a ser aberta.</param> | |
| public static void OpenFolderAndBringToFront(string path) | |
| { | |
| try | |
| { | |
| var process = Process.Start("explorer.exe", path); | |
| // Dá um tempo para o Explorer carregar a janela | |
| Thread.Sleep(500); | |
| if (process != null && !process.HasExited) | |
| { | |
| // Tenta colocar a janela na frente | |
| SetForegroundWindow(process.MainWindowHandle); | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| Debug.WriteLine("Erro ao abrir pasta: " + ex.Message); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment