Application that can open program in full screen?
Asked Answered
D

2

9

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:)

Dehypnotize answered 20/1, 2011 at 3:37 Comment(0)
D
13

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

Davy answered 20/1, 2011 at 3:45 Comment(4)
That's maximised, not full screen. Not sure if sprintoflinz actually meant maximised, but he did say fullscreen.Steinbach
I doubt there's a way to make external processes fullscreen... There technically isn't even a way to do that for C# Windows forms. You have to use a combination of different things to "fake it".Lineman
@Michael: What's the difference between "maximized" and "full screen"? That the taskbar is hidden?Deprave
Full screen hides the task bar and window chrome. Think full screen for first person shooters.Steinbach
H
1

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.

Hilltop answered 13/5, 2022 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.