Example #1
0
        /// <summary>
        /// Getting the icon title Log Font
        /// </summary>
        /// <param name="lf">
        /// The LogFont reference. The output parameter.
        /// </param>
        /// <returns><b>false</b> If failed to get the font.</returns>
        public static bool GetItemIconTitleLogFont(ref Win32API.LOGFONT lf)
        {
            Version osVersion        = Environment.OSVersion.Version;
            Version frameworkVersion = Environment.Version;

            if (osVersion.Major == 5 && osVersion.Minor == 2 &&
                frameworkVersion.Major == 1 && frameworkVersion.Minor <= 1)
            {
                //When working on Windows 2003 (Framework 1.0 and 1.1),
                //the SystemParametersInfo function invocation causes
                //ExecutionEngineException.
                //In this case, set the font parameters by default.

                lf.lfFaceName[0]  = 'T';
                lf.lfFaceName[2]  = 'a';
                lf.lfFaceName[4]  = 'h';
                lf.lfFaceName[6]  = 'o';
                lf.lfFaceName[8]  = 'm';
                lf.lfFaceName[10] = 'a';

                const byte DEFAULT_CHARSET = 1;
                const int  FW_NORMAL       = 400;
                lf.lfCharSet        = DEFAULT_CHARSET;
                lf.lfClipPrecision  = 0;
                lf.lfEscapement     = 0;
                lf.lfHeight         = -11;
                lf.lfItalic         = 0;
                lf.lfOrientation    = 0;
                lf.lfOutPrecision   = 0;
                lf.lfPitchAndFamily = 0;
                lf.lfQuality        = 0;
                lf.lfUnderline      = 0;
                lf.lfStrikeOut      = 0;
                lf.lfWeight         = FW_NORMAL;
                lf.lfWidth          = 0;
            }
            else
            {
                if (Win32API.SystemParametersInfo
                        (Win32API.SPI_GETICONTITLELOGFONT, (uint)
                        System.Runtime.InteropServices.Marshal.SizeOf(lf), ref lf,
                        0) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Getting the icon title font
        /// </summary>
        /// <param name="font">The font reference. The output parameter.</param>
        public static Font GetItemIconTitleFont()
        {
            Win32API.LOGFONT lf = new Win32API.LOGFONT();
            lf.lfFaceName = new char[32];

            Font font = null;

            if (Utils.GetItemIconTitleLogFont(ref lf))
            {
                try
                {
                    font = Font.FromLogFont(lf);
                    return(font);
                }
                catch (ArgumentException)
                {
                }
            }
            font = new Font("Tahoma", 11.0f, FontStyle.Regular);
            return(font);
        }