I need to open nNtepad to a specific size and in a specific position on the screen.
How can I do that from C#?
I'd appreciate a code sample.
You can pinvoke MoveWindow. Like this:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program {
static void Main(string[] args) {
var prc = Process.Start("notepad.exe");
prc.WaitForInputIdle();
bool ok = MoveWindow(prc.MainWindowHandle, 0, 0, 300, 200, false);
if (!ok) throw new System.ComponentModel.Win32Exception();
}
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With