Should I call Application.EnableVisualStyles() on terminal services?

ⅰ亾dé卋堺 提交于 2019-12-12 17:21:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6007879/should-i-call-application-enablevisualstyles-on-terminal-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!