最大化控制台窗口-C# [英] Maximizing console window - C#

查看:253
本文介绍了最大化控制台窗口-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#上的控制台应用程序,我需要最大程度地打开控制台.当我刚刚点击控制台窗口上的最大化按钮时,它仅在高度而不是宽度上最大化.我尝试使用以下代码:

I'm working on a console application on C# and I need to open the console maximized. When I just hit the maximize button on the console window, it maximizes only on height and not in width. I tried to use the following code :

   Console.WindowWidth = 150;
   Console.WindowHeight = 61;

在我的计算机上几乎可以按照我的要求工作,但在其他一些计算机上却报错. 我应该怎么做才能最大化控制台?

Which works almost as I want on my computer but gives error on some other computers. What should I do to maximize the console?

推荐答案

不能使用CLR.需要导入Win32 API调用并戳出您的容器窗口.以下内容可能会有所帮助.

Can't with the CLR. Need to import Win32 API calls and poke your container window. The following might help.

using System.Diagnostics;
using System.Runtime.InteropServices;

[DllImport("user32.dll")]
public static extern bool ShowWindow(System.IntPtr hWnd, int cmdShow);

private static void Maximize()
{
    Process p = Process.GetCurrentProcess();
    ShowWindow(p.MainWindowHandle, 3); //SW_MAXIMIZE = 3
}

这篇关于最大化控制台窗口-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆