コード例 #1
0
ファイル: GlassLabel.cs プロジェクト: rvs76/Maranate
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            if (Glass.IsDesktopCompositionEnabled())
            {
                return;
            }

            base.OnPaintBackground(pevent);
        }
コード例 #2
0
ファイル: GlassLabel.cs プロジェクト: rvs76/Maranate
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            try
            {
                if (Glass.IsDesktopCompositionEnabled())
                {
                    var form  = this.FindForm();
                    var glass = new GlassText();
                    glass.DrawTextOnGlass(this.FindForm().Handle, Text, Font, Bounds, TextAlign, 8);
                    glass.DrawTextOnGlass(e.Graphics, Text, Font, ClientRectangle, TextAlign, 8);

                    return;
                }
            }
            catch (DllNotFoundException)
            {
            }
            base.OnPaint(e);
        }
コード例 #3
0
        private void DrawTextOnGlassInternal(IntPtr destdc, String text, Font font, Rectangle ctlrct, ContentAlignment textAlign, int iglowSize)
        {
            if (Glass.IsDesktopCompositionEnabled())
            {
                RECT rc  = new RECT();
                RECT rc2 = new RECT();

                var iglowExpand = (int)(iglowSize * 0.5);
                //iglowExpand = 0;

                //make it larger to contain the glow effect
                rc.left   = ctlrct.Left - iglowExpand;
                rc.right  = ctlrct.Right;// + iglowExpand;
                rc.top    = ctlrct.Top - iglowExpand;
                rc.bottom = ctlrct.Bottom + iglowExpand;

                //Just the same rect with rc,but (0,0) at the lefttop
                rc2.left   = iglowExpand;
                rc2.top    = iglowExpand;
                rc2.right  = rc.right - rc.left;// - iglowExpand;
                rc2.bottom = rc.bottom - rc.top - iglowExpand;

                IntPtr Memdc = CreateCompatibleDC(destdc);   // Set up a memory DC where we'll draw the text.
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                //int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format
                TextFormatFlags uFormat = TextFormatFlags.NoPrefix;   //text format
                //if ((textAlign == ContentAlignment.TopCenter) ||
                //    (textAlign == ContentAlignment.MiddleCenter) ||
                //    (textAlign == ContentAlignment.BottomCenter))
                //    uFormat |= TextFormatFlags.HorizontalCenter;

                //if ((textAlign == ContentAlignment.TopRight) ||
                //    (textAlign == ContentAlignment.MiddleRight) ||
                //    (textAlign == ContentAlignment.BottomRight))
                //    uFormat |= TextFormatFlags.Right;

                //if ((textAlign == ContentAlignment.MiddleLeft) ||
                //    (textAlign == ContentAlignment.MiddleCenter) ||
                //    (textAlign == ContentAlignment.MiddleRight))
                //    uFormat |= TextFormatFlags.VerticalCenter;

                //if ((textAlign == ContentAlignment.BottomLeft) ||
                //    (textAlign == ContentAlignment.BottomCenter) ||
                //    (textAlign == ContentAlignment.BottomRight))
                //    uFormat |= TextFormatFlags.Bottom;

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight      = -(rc.bottom - rc.top);    // negative because DrawThemeTextEx() uses a top-down DIB
                dib.bmiHeader.biWidth       = rc.right - rc.left;
                dib.bmiHeader.biPlanes      = 1;
                dib.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount    = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {
                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);

                            DTTOPTS dttOpts = new DTTOPTS();
                            dttOpts.dwSize    = (uint)Marshal.SizeOf(typeof(DTTOPTS));
                            dttOpts.dwFlags   = DTT_COMPOSITED | DTT_GLOWSIZE;
                            dttOpts.iGlowSize = iglowSize;

                            DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, (int)uFormat, ref rc2, ref dttOpts);

                            BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.Message);
                        }

                        //using (var image = GetImageFromHBitmap(bitmap))
                        //{
                        //    image.Save(@"d:\temp\sqlupdate.png", System.Drawing.Imaging.ImageFormat.Png);
                        //}

                        //Remember to clean up
                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);
                    }
                }
            }
        }