在C#控制台应用程序中,如何阻止全屏?

问题描述 投票:0回答:1

在C#控制台应用程序中,如何阻止全屏?

我想阻止在全屏显示后调整控制台窗口大小或移动控制台窗口的可能性。

using System;
using System.Runtime.InteropServices;

class Program
{
    #region Dll Import
    [DllImport("user32.dll")]
    private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    [DllImport("kernel32.dll")]
    private static extern IntPtr GetConsoleWindow();
    #endregion

    static void Main()
    {
        //int SW_SHOWMAXIMIZED = 3;
        IntPtr hWnd = GetConsoleWindow();
        if(hWnd != IntPtr.Zero) ShowWindow(hWnd, 3);
    }
}
c# console-application screen fullscreen
1个回答
0
投票

Windows 控制台 API 不直接支持阻止调整控制台窗口大小或移动控制台窗口的可能性。控制台窗口的行为由 Windows 操作系统控制。

如果您想创建一个行为类似于控制台窗口但不允许调整大小或移动的自定义 UI,您可以考虑创建 Windows 窗体或 WPF 应用程序而不是纯控制台应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.