示例#1
0
        public static void PaintShadowTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf, Color textColor, Color shadowColor, bool copySourceBackground)
        {
            Point transformPoint = new Point();
            using (Matrix trans = g.Transform)
            {
                Point[] pts = new Point[1];
                pts[0] = transformPoint;
                trans.TransformPoints(pts);
                transformPoint = pts[0];
            }

            IntPtr hdc = g.GetHdc();
            const int SRCCOPY = 0x00CC0020;
            try
            {
                IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
                try
                {
                    WinApi.BITMAPINFO info = new WinApi.BITMAPINFO();
                    info.biWidth = rect.Width;
                    info.biHeight = -rect.Height;
                    info.biPlanes = 1;
                    info.biBitCount = 32;
                    info.biSize = Marshal.SizeOf(info);
                    IntPtr dib = WinApi.CreateDIBSection(hdc, info, 0, 0, IntPtr.Zero, 0);
                    WinApi.SelectObject(memdc, dib);

                    IntPtr fontHandle = font.ToHfont();
                    WinApi.SelectObject(memdc, fontHandle);

                    Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height));
                    System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                    Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
                    dttOpts.crText = new Themes.COLORREF(shadowColor);
                    dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED |
                        (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
                    dttOpts.dwSize = Marshal.SizeOf(dttOpts);

                    if (copySourceBackground)
                        WinApi.BitBlt(memdc, 0, 0, rect.Width, rect.Height, hdc, rect.Left + transformPoint.X, rect.Top + transformPoint.Y, SRCCOPY);
                    // Shadow
                    bounds.Offset(1, 2);
                    Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
                    bounds.Offset(-1, -1);
                    dttOpts.crText = new Themes.COLORREF(textColor);
                    Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
                    //Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);

                    WinApi.BitBlt(hdc, rect.Left + transformPoint.X, rect.Top + transformPoint.Y, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);

                    WinApi.DeleteObject(fontHandle);
                    WinApi.DeleteObject(dib);
                }
                finally
                {
                    WinApi.DeleteDC(memdc);
                }
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
        }
示例#2
0
        /// <summary>
        /// Paints ribbon tab group.
        /// </summary>
        /// <param name="e">Context information</param>
        public override void PaintTabGroup(RibbonTabGroupRendererEventArgs e)
        {
            Graphics g = e.Graphics;
            Office2007RibbonTabGroupColorTable colorTable = GetColors(e.RibbonTabItemGroup);
            if (colorTable == null)
                return;
            #if FRAMEWORK20
            if (e.ItemPaintArgs.GlassEnabled)
            {
                if (e.ItemPaintArgs.CachedPaint) return;
                PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, true);
                
                Rectangle rect = e.Bounds;
                rect.Height -= 2;
                IntPtr hdc = g.GetHdc();
                Font font = e.GroupFont;
                string text = e.RibbonTabItemGroup.GroupTitle;
                ThemeTextFormat tf = GetThemeFormat();
                try
                {
                    IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
                    try
                    {
                        WinApi.BITMAPINFO bmpInfo = new WinApi.BITMAPINFO();
                        bmpInfo.biWidth = rect.Width;
                        bmpInfo.biHeight = -rect.Height;
                        bmpInfo.biPlanes = 1;
                        bmpInfo.biBitCount = 32;
                        bmpInfo.biSize = Marshal.SizeOf(bmpInfo);
                        IntPtr dib = WinApi.CreateDIBSection(hdc, bmpInfo, 0, 0, IntPtr.Zero, 0);
                        WinApi.SelectObject(memdc, dib);

                        IntPtr fontHandle = font.ToHfont();
                        WinApi.SelectObject(memdc, fontHandle);

                        Themes.RECT bounds = GetThemeTextBounds(rect);
                        System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                        Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
                        dttOpts.iGlowSize = 10;
                        dttOpts.crText = new Themes.COLORREF(colorTable.Text);
                        dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED | (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
                        if (colorTable.Background == null || colorTable.Background.IsEmpty || colorTable.Background.Start.A < 255)
                            dttOpts.dwFlags |= (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE;
                        dttOpts.dwSize = Marshal.SizeOf(dttOpts);
                        
                        // Draw Background
                        using (Graphics gb = Graphics.FromHdc(memdc))
                        {
                            PaintTabGroupBackground(gb, colorTable, new Rectangle(0, 0, rect.Width, rect.Height + 2), new Rectangle(0, 0, rect.Width, rect.Height + 2), true);
                        }
                        
                        Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
                        

                        const int SRCCOPY = 0x00CC0020;
                        WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);

                        WinApi.DeleteObject(fontHandle);
                        WinApi.DeleteObject(dib);
                    }
                    finally
                    {
                        WinApi.DeleteDC(memdc);
                    }
                }
                finally
                {
                    g.ReleaseHdc(hdc);
                }
                return;
            }
            #endif

            PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, false);
            ElementStyle style = e.RibbonTabItemGroup.Style; //.Copy();
            Color styleTextColor = style.TextColor;
            Color styleTextShadowColor = style.TextShadowColor;
            Point styleTextShadowOffset = style.TextShadowOffset;
            style.FreezeEvents = true;
            style.TextColor = colorTable.Text;
            style.TextShadowColor = Color.Empty;
            style.TextShadowOffset = Point.Empty;

            ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, e.Graphics, GetTextBounds(e));
            ElementStyleDisplay.PaintText(info, e.RibbonTabItemGroup.GroupTitle, e.GroupFont, false, e.RibbonTabItemGroup.Style.TextFormat | GetTextFormat());

            style.TextColor = styleTextColor;
            style.TextShadowColor = styleTextShadowColor;
            style.TextShadowOffset = styleTextShadowOffset;
            style.FreezeEvents = false;
        }
示例#3
0
        public static void PaintTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf, Color textColor, bool copySourceBackground, bool renderGlow, int glowSize)
        {
            IntPtr hdc = g.GetHdc();
            const int SRCCOPY = 0x00CC0020;
            try
            {
                IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
                try
                {
                    WinApi.BITMAPINFO info = new WinApi.BITMAPINFO();
                    info.biWidth = rect.Width;
                    info.biHeight = -rect.Height;
                    info.biPlanes = 1;
                    info.biBitCount = 32;
                    info.biSize = Marshal.SizeOf(info);
                    IntPtr dib = WinApi.CreateDIBSection(hdc, info, 0, 0, IntPtr.Zero, 0);
                    WinApi.SelectObject(memdc, dib);

                    IntPtr fontHandle = font.ToHfont();
                    WinApi.SelectObject(memdc, fontHandle);

                    Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height));
                    System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                    Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
                    dttOpts.iGlowSize = glowSize;
                    dttOpts.crText = new Themes.COLORREF(textColor);
                    dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED |
                        (renderGlow ? (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE : 0) |
                        (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
                    dttOpts.dwSize = Marshal.SizeOf(dttOpts);

                    if (copySourceBackground)
                        WinApi.BitBlt(memdc, 0, 0, rect.Width, rect.Height, hdc, rect.Left, rect.Top, SRCCOPY);

                    Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);

                    WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);

                    WinApi.DeleteObject(fontHandle);
                    WinApi.DeleteObject(dib);
                }
                finally
                {
                    WinApi.DeleteDC(memdc);
                }
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
        }