打开记事本到屏幕上的特定位置,并达到所需的大小?

Nan*_*ano 3 c# winapi resize

我需要将nNtepad打开到特定大小并在屏幕上的特定位置.

我怎么能用C#做到这一点?

我很感激代码示例.

Han*_*ant 10

你可以按下MoveWindow.像这样:

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);
}
Run Code Online (Sandbox Code Playgroud)

  • 我的水晶球无法对注释进行反向工程,它遭遇了六次语法错误异常,一点记录.不知何故,它似​​乎与原始问题或记事本没什么关系.它建议一个精心设计的新问题. (4认同)