none
System.Diagnostics.Process.Start("notepad.exe") - how do I resize and reposition the notepad?

    Question

  • Hi guys,
    I have a button on my form which allows users to call the notepad. However, I would like to make the notepad's winform size smaller when it starts up. Also, I would like it to start in the center screen. How can I achieve with code? Thanks a lot!

    Regards
    Zheng
    Thank you, msdn =) 99.9% of my questions have been answered :D Congrats on your promotion to Microsoft Partner, Arjun!
    Friday, May 08, 2009 2:55 AM

Answers

  • The Process instace returned by Process.Start has a MainWindowHandle property you can use to get the window handle to the newly started application's main window (but note that it doesn't always work reliably with all applications). You can use that handle with functions like MoveWindow to reposition the window.
    Mattias, C# MVP
    Friday, May 08, 2009 11:46 AM

All replies

  • Do you have to rely on Notepad? While it's possible to move and resize the Notepad window using Windows API functions, it may be quicker and easier for you to roll your own Form with a Textbox on it and use that to display the file content instead. That would give you full control over its appearance. 
    Mattias, C# MVP
    Friday, May 08, 2009 8:38 AM
  • Hi Mattias,

    I have another reason for asking such a question. I have another button for calling the window calculator as well. If no one could help me about the resizing notepad window question, I was hoping that someone would tell me how to reposition it, so that I could apply it on the calc.exe as well :) Thanks a lot, Mattias.

    Thank you, msdn =) 99.9% of my questions have been answered :D Congrats on your promotion to Microsoft Partner, Arjun!
    Friday, May 08, 2009 9:31 AM
  • The Process instace returned by Process.Start has a MainWindowHandle property you can use to get the window handle to the newly started application's main window (but note that it doesn't always work reliably with all applications). You can use that handle with functions like MoveWindow to reposition the window.
    Mattias, C# MVP
    Friday, May 08, 2009 11:46 AM