Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- namespace BringToFront
- {
- public partial class Form1 : Form
- {
- [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
- public static extern IntPtr FindWindow(String className, String windowName);
- [DllImport("USER32.DLL")]
- public static extern bool SetForegroundWindow(IntPtr hWnd);
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- bringToFront(comboBox1.SelectedItem.ToString());
- }
- catch
- {
- MessageBox.Show("Please choose a Process Name");
- }
- }
- public static void bringToFront(string title)
- {
- IntPtr handle = FindWindow(null, title);
- if (handle == IntPtr.Zero)
- {
- return;
- }
- SetForegroundWindow(handle);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (checkBox1.Checked)
- {
- bringToFront(comboBox1.SelectedItem.ToString());
- }
- }
- private void comboBox1_Click(object sender, EventArgs e)
- {
- comboBox1.Items.Clear();
- Process[] process = Process.GetProcesses();
- foreach (Process processes in process)
- {
- if (!String.IsNullOrEmpty(processes.MainWindowTitle))
- comboBox1.Items.Add(processes.ProcessName);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment