Esempio 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);
     }
 }