Exemple #1
0
 public static int DrawShadowText(Graphics g, Rectangle bounds, string text, ThemeTextFormat format, Color textColor, Color shadowColor, int shadowOffsetX, int shadowOffsetY)
 {
     int result = 0;
     IntPtr hdc = g.GetHdc();
     try
     {
         RECT r = new RECT(bounds);
         result = DrawShadowText(hdc, text, (uint)text.Length, ref r, (int)format, new COLORREF(textColor), new COLORREF(shadowColor), shadowOffsetX, shadowOffsetY);
     }
     finally
     {
         g.ReleaseHdc(hdc);
     }
     return result;
 }
Exemple #2
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);
            }
        }
Exemple #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);
            }
        }
Exemple #4
0
        //private void PaintGlassTextTheme(Graphics g, string text, Font font, Rectangle captionRect, ItemPaintArgs pa)
        //{
        //    //TextDrawing.DrawString(g, text, font, SystemColors.ActiveCaptionText, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
        //    //Bitmap bmp = new Bitmap(captionRect.Width, captionRect.Height);
        //    //bmp.MakeTransparent();
        //    //using (Graphics gb = Graphics.FromImage(bmp))
        //    {
        //        //gb.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, bmp.Width, bmp.Height));
        //        //gb.FillRectangle(new SolidBrush(Color.FromArgb(186, Color.White)), new Rectangle(0, 0, bmp.Width, bmp.Height));
        //        //g.ResetTransform();
        //        //e.ItemPaintArgs.ThemeWindow.DrawText(g, text, font, captionRect,
        //        //    ThemeWindowParts.Caption, ThemeWindowStates.CaptionActive);
        //        //g.ResetTransform();
        //        Themes.DTTOPTS options = new Themes.DTTOPTS();
        //        options.iGlowSize = 12;
        //        options.crText = new Themes.COLORREF(SystemColors.ActiveCaptionText);
        //        options.dwFlags = (int)(Themes.DTT_VALIDBITS.DTT_TEXTCOLOR |
        //            Themes.DTT_VALIDBITS.DTT_APPLYOVERLAY |
        //            Themes.DTT_VALIDBITS.DTT_COMPOSITED | Themes.DTT_VALIDBITS.DTT_GLOWSIZE
        //                                                                                     );
        //        pa.ThemeWindow.DrawTextEx(g, text, font, captionRect,
        //            ThemeWindowParts.Caption, ThemeWindowStates.CaptionActive,
        //            ThemeTextFormat.Center | ThemeTextFormat.VCenter | ThemeTextFormat.EndEllipsis | ThemeTextFormat.NoPrefix |
        //            ThemeTextFormat.SingleLine,
        //            options);
        //        //g.ResetTransform();
        //    }

        //    //bmp.MakeTransparent(Color.Black);
        //    //g.DrawImage(bmp, captionRect.Location);
        //    //bmp.Save(@"TitleImage.png", System.Drawing.Imaging.ImageFormat.Png);
        //    //bmp.Dispose();
        //}
#if FRAMEWORK20
        public static void PaintTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf)
        {
            PaintTextOnGlass(g, text, font, rect, tf, SystemColors.ControlText, false, true, 16);
        }
Exemple #5
0
		public void DrawText(Graphics g, string text, Font font, Rectangle layoutRect, ThemeHeaderParts part, ThemeHeaderStates state, ThemeTextFormat format)
		{
			InternalDrawText(g,text,font,layoutRect,part,state,format,false);
		}
Exemple #6
0
		public void DrawText(Graphics g, string text, Font font, Rectangle layoutRect, ThemeExplorerBarParts part, ThemeExplorerBarStates state, ThemeTextFormat format, bool drawdisabled)
		{
			InternalDrawText(g,text,font,layoutRect,part,state,format,drawdisabled);
		}
Exemple #7
0
        protected virtual void InternalDrawTextEx(Graphics g, string text, Font font, Rectangle layoutRect, ThemePart part, ThemeState state, ThemeTextFormat format, DTTOPTS options)
        {
            RECT rDraw=new RECT(layoutRect);
			IntPtr hdc=g.GetHdc();
			IntPtr hFont=font.ToHfont();
            IntPtr old=SelectObject(hdc,hFont);
			//int hresult=DrawThemeText(m_hTheme,hdc,part.Value,state.Value,text,text.Length,(int)format,(drawdisabled?1:0),ref rDraw);
            options.dwSize = Marshal.SizeOf(options);
            int hresult = DrawThemeTextEx(m_hTheme, hdc, part.Value, state.Value, text, text.Length, (int)format, ref rDraw, ref options);

			SelectObject(hdc,old);
            WinApi.DeleteObject(hFont);
			g.ReleaseHdc(hdc);
        }
Exemple #8
0
 public void DrawTextEx(Graphics g, string text, Font font, Rectangle layoutRect, ThemePart part, ThemeState state, ThemeTextFormat format, DTTOPTS options)
 {
     InternalDrawTextEx(g, text, font, layoutRect, part, state, format, options);
 }