How to get and set the window position of another application in C#

James picture James · Sep 1, 2009 · Viewed 46.3k times · Source

How can I get and set the position of another application using C#?

For example, I would like to get the top left hand coordinates of Notepad (let’s say it's floating somewhere at 100,400) and the position this window at 0,0.

What's the easiest way to achieve this?

Answer

DataDink picture DataDink · Sep 1, 2009

I actually wrote an open source DLL just for this sort of thing. Download Here

This will allow you to find, enumerate, resize, reposition, or do whatever you want to other application windows and their controls. There is also added functionality to read and write the values/text of the windows/controls and do click events on them. It was basically written to do screen scraping with - but all the source code is included so everything you want to do with the windows is included there.