简体   繁体   中英

Application that can open program in full screen?

I need to make an application that starts new program (ex. notepad) in fullscreen mode. Can I do that in c#?

I'd appreciate a code sample.Thanks:)

You can use Process.Start with a ProcessStartInfo object which has a WindowStyle property. You can set that property so that the window starts maximized.

Adapted from the example at Process.Start :

ProcessStartInfo startInfo = new ProcessStartInfo("notepad.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(startInfo);

If the process is already running, see here

F11 key is most often used to enter and exit fullscreen mode, so after program starts, you can call User32.SendInput WinApi (use PInvoke.User32 from Nuget).

   static async Task Main(string[] args)
    {
        StartProcess(_Config.FileName, _Config.Args);
        await Task.Delay(_Config.Delay);
        SendKey_F11();
    }

    static void StartProcess(string fileName, string args)
    {
        new Process()
        {
            StartInfo = new ProcessStartInfo()
            {
                FileName = fileName,
                Arguments = args
            }
        }
        .Start();
    }

    static void SendKey_F11()
    {
        PInvoke.User32.INPUT inp = new PInvoke.User32.INPUT();
        inp.type = PInvoke.User32.InputType.INPUT_KEYBOARD;
        inp.Inputs.ki.wVk = PInvoke.User32.VirtualKey.VK_F11;
        inp.Inputs.ki.wScan = PInvoke.User32.ScanCode.F11;

        PInvoke.User32.SendInput(1, new[] { inp }, 40);
    }

In the same way you can call any other hotkey command to enter fullscreen mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM