我应该叫Application.EnableVisualStyles()上的终端服务?终端、Application、EnableVisualStyles

2023-09-06 06:25:46 作者:櫻花雨落巴黎岸

在一个终端服务/ Citrix环境中,我应该叫 Application.EnableVisualStyles()在我的.net 3.5 WinForms应用程序时,我的程序 开始?或者说,它是更好地做,要不要?

我要寻找能提供最佳性能的选项,不需要绘制任何控件 主题。

解决方案   

视觉样式颜色,字体,和其他视觉元素,形成一个操作系统的主题。控制将视觉样式绘制如果控制和操作系统支持。要产生作用,EnableVisualStyles()必须在创建应用程序中的任何控件之前被调用;通常,EnableVisualStyles()是在主函数的第一行。

因此​​,如果您需要在您的应用程序的外观与当前操作系统的主题,你需要调用此。如果Windows经典外观是不够的,你可以跳过这一点。我个人从来没有启用视觉样式为我的服务器只有应用程序(如控制面板,等等)。

下面是未启用视觉样式的配置工具。这是很好找我这种方式使 EnableVisualStyles 被忽略:

快速查看 Application.EnableVisualStyles()方法与反射的方法 EnableVisualStyles透露跌破code - > EnableVisualStylesInternal - > CreateActivati​​onContext

 如果(contextCreationSucceeded&安培;!&安培; OSFeature.Feature.Is present(OSFeature.Themes))
    {
      enableThemingActivati​​onContext =新ACTCTX();
      enableThemingActivati​​onContext.cbSize = Marshal.SizeOf(typeof运算(ACTCTX));
      enableThemingActivati​​onContext.lpSource = DllPath的;
      enableThemingActivati​​onContext.l presourceName =(IntPtr的)nativeResourceManifestID;
      enableThemingActivati​​onContext.dwFlags = 8;
      hActCtx = CreateActCtx(REF enableThemingActivati​​onContext);
      !contextCreationSucceeded = hActCtx =新的IntPtr(-1);
    }
 

如果 OSFeature.Feature.Is present(OSFeature.Themes)返回false, EnableVisualStyles 具有绝对没有任何影响,所以要求与否没什么区别。

2017 2018申请季SAO系统今日开放 美高申请前不得不知的3大方面

In a terminal services/citrix environment, should I call Application.EnableVisualStyles() in my .NET 3.5 WinForms app when my program starts? Or, is it better to refrain from doing that?

I am looking for the option that gives the best performance, and do not need any controls drawn with themes.

解决方案

Visual styles are the colors, fonts, and other visual elements that form an operating system theme. Controls will draw with visual styles if the control and the operating system support it. To have an effect, EnableVisualStyles() must be called before creating any controls in the application; typically, EnableVisualStyles() is the first line in the Main function.

So, if you need to have your application look in line with the current OS theme, you need to call this. If the classic Windows look is enough for you, you can skip this. I personally never enable visual styles for my server-only apps (like control panels, etc.).

Below is a configurator tool without the visual styles enabled. It's good looking for me this way so EnableVisualStyles was skipped:

A quick look into Application.EnableVisualStyles() method with reflector revealed below code in the method EnableVisualStyles -> EnableVisualStylesInternal -> CreateActivationContext:

if (!contextCreationSucceeded && OSFeature.Feature.IsPresent(OSFeature.Themes))
    {
      enableThemingActivationContext = new ACTCTX();
      enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(ACTCTX));
      enableThemingActivationContext.lpSource = dllPath;
      enableThemingActivationContext.lpResourceName = (IntPtr) nativeResourceManifestID;
      enableThemingActivationContext.dwFlags = 8;
      hActCtx = CreateActCtx(ref enableThemingActivationContext);
      contextCreationSucceeded = hActCtx != new IntPtr(-1);
    }

If OSFeature.Feature.IsPresent(OSFeature.Themes) returns false, EnableVisualStyles has absolutely no effect so calling it or not makes no difference.