Click here to Skip to main content
15,895,793 members
Articles / Programming Languages / C#

XPanderControls

Rate me:
Please Sign up or sign in to vote.
4.93/5 (106 votes)
27 Nov 2008CPOL3 min read 284.3K   29.2K   378  
Outlook 2007 styled expandable and collapsible panels and panel collections for grouping collections of controls.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.IO;
using System.Text.RegularExpressions;

namespace BSE.Windows.Forms
{
	static class DisplayInformation
	{
		#region FieldsPrivate

		[ThreadStatic]
        private static bool m_bIsThemed;
        private const string m_strRegExpression = @".*\.msstyles$";

		#endregion

		#region Properties

        internal static bool IsThemed
        {
            get { return m_bIsThemed; }
        }
		#endregion

		#region MethodsPrivate

		static DisplayInformation()
		{
			SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(DisplayInformation.OnUserPreferenceChanged);
			DisplayInformation.SetScheme();
		}

		private static void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
		{
			DisplayInformation.SetScheme();
		}

		private static void SetScheme()
		{
			if (VisualStyleRenderer.IsSupported)
			{
				if (!VisualStyleInformation.IsEnabledByUser)
				{
					return;
				}
				StringBuilder stringBuilder = new StringBuilder(0x200);
				int iResult = NativeMethods.GetCurrentThemeName(stringBuilder, stringBuilder.Capacity, null, 0, null, 0);
                if (iResult == 0)
                {
                    Regex regex = new Regex(m_strRegExpression);
                    m_bIsThemed = regex.IsMatch(Path.GetFileName(stringBuilder.ToString()));
                }
			}
		}
		#endregion

		static class NativeMethods
		{
			[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
			public static extern int GetCurrentThemeName(StringBuilder pszThemeFileName, int dwMaxNameChars, StringBuilder pszColorBuff, int dwMaxColorChars, StringBuilder pszSizeBuff, int cchMaxSizeChars);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions