0

I'm working on a project. I am writing a program in Windows 10+Visual Studio 2019. In my C# program, I want to move the position of the Explorer window that is displayed on the screen. For example, let's say I have a folder named C:\Users\username\Documents\datawindow open. The screen position is X=100, Y=100. How can I move the position of this window to X=500, Y=500?

In the code below, I have found the Process that contains datawindow. I want to change the window position of this process from my C# program. Please give me your best advice.

    public class WindowLocation : Form
{
    public void SetExplorerWindowLocation()
    {
        foreach (Process p in Process.GetProcesses().Where(process => process.ProcessName=="explorer"))
        {
            Console.WriteLine("ProcessName:" + p.ProcessName);
            Console.WriteLine("WindowTitle:" + p.MainWindowTitle);
        }
    }
}
  • 1
    Use p.MainWindowHandle to get the HWND of the window and call SetWindowPos: https://stackoverflow.com/questions/1190423/using-setwindowpos-in-c-sharp-to-move-windows-around – kol Jul 09 '21 at 12:34
  • 1
    The Shell allows you to enumerate all open Shell Views. It is more efficient and more robust than checking the process name of every process in the system: [A big little program: Monitoring Internet Explorer and Explorer windows, part 1: Enumeration](https://devblogs.microsoft.com/oldnewthing/20130610-00/?p=4133). – IInspectable Jul 09 '21 at 17:13
  • Thanks for your comment. I was able to do it using the answer method in that link. I appreciate it. –  Jul 10 '21 at 01:56

0 Answers0