Ejemplo n.º 1
0
 private static void DrawOnHDC(IntPtr compatHdc, string text, Font font, Padding internalBounds, Rectangle bounds, Color color, TextFormatFlags formatFlags, AeroLabelMode mode, IThemeTextOption[] options)
 {
     if (SystemSupports.IsAeroSupport && mode == AeroLabelMode.Aero)
     {
         IntPtr hFont = font.ToHfont();
         NativeMethod.SelectObject(compatHdc, hFont);
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
         DTTOPTS             dttOpts  = default(DTTOPTS);
         dttOpts.dwSize  = Marshal.SizeOf(dttOpts);
         dttOpts.dwFlags = (DTTOPSFlags)8193;
         dttOpts.crText  = ColorTranslator.ToWin32(color);
         for (int i = 0; i < options.Length; i++)
         {
             IThemeTextOption op = options[i];
             op.Apply(ref dttOpts);
         }
         RECT RECT = new RECT(internalBounds.Left, internalBounds.Top, bounds.Width - internalBounds.Right, bounds.Height - internalBounds.Bottom);
         int  ret  = NativeMethod.DrawThemeTextEx(renderer.Handle, compatHdc, 0, 0, text, -1, (int)formatFlags, ref RECT, ref dttOpts);
         if (ret != 0)
         {
             Marshal.ThrowExceptionForHR(ret);
         }
         NativeMethod.DeleteObject(hFont);
     }
     else
     {
         Graphics gc = Graphics.FromHdc(compatHdc);
         gc.TextRenderingHint = TextRenderingHint.AntiAlias;
         using (SolidBrush sb = new SolidBrush(Color.FromArgb(254, color)))
             gc.DrawString(text, font, sb, bounds);
     }
 }
Ejemplo n.º 2
0
        protected IThemeTextOption[] CreateOptions()
        {
            IThemeTextOption[] options = new IThemeTextOption[this.CountOptions()];
            int curr = 0;

            if (this._glowEnable)
            {
                options[curr] = new GlowOption(this._glowSize);
                curr++;
            }
            if (this._shadowEnable)
            {
                options[curr] = new ShadowOption(this._shadowColor, this._shadowOffset, this._shadowType);
                curr++;
            }
            if (!this._overlayEnable)
            {
                options[curr] = new OverlayOption(this._overlayEnable);
                curr++;
            }
            if (this._borderEnable)
            {
                options[curr] = new BorderOption(this._borderColor, this._borderSize);
                curr++;
            }
            return(options);
        }