Exemple #1
0
 /// <summary>
 /// Brings the thread that created the specified application into the foreground and activates the
 /// window. Keyboard input is directed to the window, and various visual cues are changed for
 /// the user. The system assigns a slightly higher priority to the thread that created the
 /// foreground window than it does to other threads.
 /// </summary>
 /// <param name="selector">If returns true, the window is activated.</param>
 public static void BringToFront(Func <Process, bool> selector)
 {
     foreach (var item in Processes.Where(x => x.MainWindowHandle != IntPtr.Zero))
     {
         if (selector(item))
         {
             UnsafeNative.ActivateWindow(item.MainWindowHandle);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Brings the thread that created the specified application into the foreground and activates the
        /// window. Keyboard input is directed to the window, and various visual cues are changed for
        /// the user. The system assigns a slightly higher priority to the thread that created the
        /// foreground window than it does to other threads.
        /// <para/>
        /// This will only activate the first application instance in the list, if multiple instances are active.
        /// </summary>
        /// <returns>Returns true if successfull; otherwise false</returns>
        public static bool BringToFront()
        {
            var process = Processes.FirstOrDefault(x => x.MainWindowHandle != IntPtr.Zero);

            if (process != null)
            {
                UnsafeNative.ActivateWindow(process.MainWindowHandle);
                return(true);
            }

            return(false);
        }