简体   繁体   English

检查winforms是否可以在单声道上显示

[英]Check if winforms can be displayed on mono

I am making a console application that displays some data in windows form popups primarily for development or to configure it. 我正在制作一个控制台应用程序,该程序在Windows窗体弹出窗口中显示一些数据,主要用于开发或配置。 However, when deployed it is to be ran in a command line only environment, which will not be able to display the forms. 但是,在部署时,它将只能在仅命令行的环境中运行,该环境将无法显示表单。 I would like to know if there is a way to detect whether or not it is possible to display these forms so I can display the data in a different format or print an explanation if the data cannot be displayed (one of the forms is an image preview). 我想知道是否有一种方法可以检测是否可以显示这些表格,以便可以以其他格式显示数据或在无法显示数据时打印说明(其中一个表格是图像)预习)。

Yes sir, i would like to give you two Methods, for the case "Mono": 是的,先生,对于“单声道”,我想给您两个方法:

This Checks, if your in Mono Runtime: 这会检查您是否在Mono Runtime中:

private Boolean IsMonoRuntime()
{
      return (Type.GetType("Mono.Runtime") != null);
}

This gives you the Mono-Version (Linux Package) or String.Empty: 这将为您提供Mono版本(Linux软件包)或String.Empty:

    private String GetMonoRuntime()
{
    Type type = Type.GetType("Mono.Runtime");

    if (type != null)
    {
        MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
        if (displayName == null)
            return "Unix/Linux + Mono";
        else
            return "Unix/Linux + Mono " + displayName.Invoke(null, null);
    }

    return String.Empty;
}

I hope its whay ou needed. 我希望它的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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