This question already has an answer here:
- Bring to forward window when minimized 2 answers
Couldn't find any good answer on this topic, so maybe someone can help me out. I'm making a small personal program where I want to bring a certain application to the foreground. It already works, but there is one small problem. When the process is minimized my code doesn't work. The process wont get showed on the foreground like it does when it is not minimized.
Here is a snippet of the code:
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("Client");
if (p.Length > 0)
{
SetForegroundWindow(p[0].MainWindowHandle);
}
else //Not Found
{
MessageBox.Show("Window Not Found!");
}
}