示例#1
0
        bool VisualStylesEnabled()
        {
            OperatingSystem os = Environment.OSVersion;
            bool isAppropriateOS = os.Platform == PlatformID.Win32NT && ((os.Version.Major == 5 && os.Version.Minor >= 1) || os.Version.Major > 5);
            bool osFeatureThemesPresent = false;
            bool osThemeDLLAvailable = false;

            if (isAppropriateOS)
            {
                Version osThemeVersion = OSFeature.Feature.GetVersionPresent(OSFeature.Themes);
                osFeatureThemesPresent = osThemeVersion != null;

                NativeMethods.DLLVersionInfo dllVersion = new NativeMethods.DLLVersionInfo();
                dllVersion.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVersionInfo));
                int temp = NativeMethods.DllGetVersion(ref dllVersion);
                osThemeDLLAvailable = dllVersion.dwMajorVersion >= 6;
            }

            return isAppropriateOS && osFeatureThemesPresent && osThemeDLLAvailable && NativeMethods.IsAppThemed() && NativeMethods.IsThemeActive();
        }
示例#2
0
		/// <summary>
		/// Returns true, when visual styles are enabled in this application.
		/// </summary>
		bool VisualStylesEnabled()
		{
			// Check if RenderWithVisualStyles property is available in the Application class (New feature in NET 2.0)
			Type t = typeof(Application);
			System.Reflection.PropertyInfo pi = t.GetProperty("RenderWithVisualStyles");
			
			if(pi == null)
			{
				// NET 1.1
				OperatingSystem os = System.Environment.OSVersion;
				if(os.Platform == PlatformID.Win32NT && (((os.Version.Major == 5) && (os.Version.Minor >= 1)) || (os.Version.Major > 5)) )
				{
					NativeMethods.DLLVersionInfo version = new NativeMethods.DLLVersionInfo();
					version.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVersionInfo));
					if(NativeMethods.DllGetVersion(ref version) == 0)
					{
						return (version.dwMajorVersion > 5) && NativeMethods.IsThemeActive() && NativeMethods.IsAppThemed();
					}
				}

				return false;
			}
			else
			{
				// NET 2.0
				bool result = (bool)pi.GetValue(null, null);
				return result;
			}
		}