コード例 #1
0
        public static void DrawTextGlow(Graphics Graphics, string text, Font fnt, Rectangle bounds, Color Clr, TextFormatFlags flags)
        {
            IntPtr zero    = IntPtr.Zero;
            IntPtr hObject = IntPtr.Zero;
            IntPtr hdc     = Graphics.GetHdc();
            IntPtr hDC     = APIs.CreateCompatibleDC(hdc);

            APIs.BITMAPINFO pbmi  = new APIs.BITMAPINFO();
            APIs.RECT       pRect = new APIs.RECT(0, 0, (bounds.Right - bounds.Left) + 30, (bounds.Bottom - bounds.Top) + 30);
            APIs.RECT       rect  = new APIs.RECT(bounds.Left - 15, bounds.Top - 15, bounds.Right + 15, bounds.Bottom + 15);
            IntPtr          ptr   = fnt.ToHfont();

            try
            {
                APIs.S_DTTOPTS      s_dttopts = new APIs.S_DTTOPTS();
                VisualStyleRenderer renderer  = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
                pbmi.bmiHeader.biSize     = Marshal.SizeOf(pbmi.bmiHeader);
                pbmi.bmiHeader.biWidth    = bounds.Width + 30;
                pbmi.bmiHeader.biHeight   = (0 - bounds.Height) - 30;
                pbmi.bmiHeader.biPlanes   = 1;
                pbmi.bmiHeader.biBitCount = 0x20;
                IntPtr ptr6 = APIs.CreateDIBSection(hdc, ref pbmi, 0, 0, IntPtr.Zero, 0);
                zero      = APIs.SelectObject(hDC, ptr6);
                hObject   = APIs.SelectObject(hDC, ptr);
                s_dttopts = new APIs.S_DTTOPTS
                {
                    dwSize    = Marshal.SizeOf(s_dttopts),
                    dwFlags   = 0x2801,
                    crText    = ColorTranslator.ToWin32(Clr),
                    iGlowSize = 0x12
                };
                APIs.DrawThemeTextEx(renderer.Handle, hDC, 0, 0, text, -1, (int)flags, ref pRect, ref s_dttopts);
                APIs.BitBlt(hdc, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, hDC, 0, 0, 0xcc0020);
                APIs.SelectObject(hDC, hObject);
                APIs.SelectObject(hDC, zero);
                APIs.DeleteDC(hDC);
                APIs.DeleteObject(ptr);
                APIs.DeleteObject(ptr6);
                Graphics.ReleaseHdc(hdc);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
            }
        }
コード例 #2
0
ファイル: MyGlassEffect.cs プロジェクト: woooowen/QiNiuMaster
 public static void DrawTextGlow(Graphics Graphics, string text, Font fnt, Rectangle bounds, Color Clr, TextFormatFlags flags)
 {
     IntPtr zero = IntPtr.Zero;
     IntPtr hObject = IntPtr.Zero;
     IntPtr hdc = Graphics.GetHdc();
     IntPtr hDC = APIs.CreateCompatibleDC(hdc);
     APIs.BITMAPINFO pbmi = new APIs.BITMAPINFO();
     APIs.RECT pRect = new APIs.RECT(0, 0, (bounds.Right - bounds.Left) + 30, (bounds.Bottom - bounds.Top) + 30);
     APIs.RECT rect = new APIs.RECT(bounds.Left - 15, bounds.Top - 15, bounds.Right + 15, bounds.Bottom + 15);
     IntPtr ptr = fnt.ToHfont();
     try
     {
         APIs.S_DTTOPTS s_dttopts = new APIs.S_DTTOPTS();
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
         pbmi.bmiHeader.biSize = Marshal.SizeOf(pbmi.bmiHeader);
         pbmi.bmiHeader.biWidth = bounds.Width + 30;
         pbmi.bmiHeader.biHeight = (0 - bounds.Height) - 30;
         pbmi.bmiHeader.biPlanes = 1;
         pbmi.bmiHeader.biBitCount = 0x20;
         IntPtr ptr6 = APIs.CreateDIBSection(hdc, ref pbmi, 0, 0, IntPtr.Zero, 0);
         zero = APIs.SelectObject(hDC, ptr6);
         hObject = APIs.SelectObject(hDC, ptr);
         s_dttopts = new APIs.S_DTTOPTS
         {
             dwSize = Marshal.SizeOf(s_dttopts),
             dwFlags = 0x2801,
             crText = ColorTranslator.ToWin32(Clr),
             iGlowSize = 0x12
         };
         APIs.DrawThemeTextEx(renderer.Handle, hDC, 0, 0, text, -1, (int)flags, ref pRect, ref s_dttopts);
         APIs.BitBlt(hdc, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, hDC, 0, 0, 0xcc0020);
         APIs.SelectObject(hDC, hObject);
         APIs.SelectObject(hDC, zero);
         APIs.DeleteDC(hDC);
         APIs.DeleteObject(ptr);
         APIs.DeleteObject(ptr6);
         Graphics.ReleaseHdc(hdc);
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
     }
 }