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

spiritoflinz
  • 91
  • 1
  • 1
  • 2

2 Answers2

14

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

Community
  • 1
  • 1
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
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.

csh
  • 21
  • 1