Exemplo n.º 1
0
        private void form_Resize(object sender, EventArgs e)
        {
            var form = sender as Form;

            if ((DesktopWindowManager.IsCompositionEnabled() && GetGlassEnabled(form)) || form.IsDesignMode())
            {
                InvalidateNonGlassClientArea(form);
            }
        }
Exemplo n.º 2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     if (!this.IsDesignMode() && SupportGlass && DesktopWindowManager.IsCompositionEnabled())
     {
         try { e.Graphics.Clear(Color.Black); } catch { }
     }
     else
     {
         if (rnd == null || !Application.RenderWithVisualStyles)
         {
             try { e.Graphics.Clear(BackColor); } catch { }
         }
         else
         {
             rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle);
         }
     }
     base.OnPaint(e);
 }
Exemplo n.º 3
0
        private void GlassifyForm(Form form, Graphics g = null)
        {
            if (!(DesktopWindowManager.IsCompositionEnabled() && GetGlassEnabled(form)) && !form.IsDesignMode())
            {
                return;
            }

            if (g == null)
            {
                g = form.CreateGraphics();
            }

            GlassFormProperties prop;

            if (!formProps.TryGetValue(form, out prop))
            {
                return;
            }

            // Paint the glass effect.
            if (prop.GlassMargins == new Padding(-1))
            {
                g.FillRectangle(Brushes.Black, form.ClientRectangle);
            }
            else
            {
                using (var r = new Region(form.ClientRectangle))
                {
                    r.Exclude(GetNonGlassArea(form, prop));
                    g.FillRegion(Brushes.Black, r);
                }
            }

            if (!form.IsDesignMode())
            {
                form.ExtendFrameIntoClientArea(prop.GlassMargins);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            try
            {
                // Setup variables
                var       useVs = rnd != null && Application.RenderWithVisualStyles;
                var       r = DeflateRect(ClientRectangle, Padding);
                var       tff = this.BuildTextFormatFlags();
                Rectangle tRect, iRect;
                ExtensionMethods.CalcImageAndTextBounds(r, Text, Font, Image, TextAlign, ImageAlign, TextImageRelation, !AutoSize, 0,
                                                        ref tff, out tRect, out iRect);

                // Draw background
                if (SupportGlass && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                {
                    e.Graphics.Clear(Color.Black);
                }
                else
                {
                    if (useVs)
                    {
                        rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle);
                    }
                    else
                    {
                        e.Graphics.Clear(BackColor);
                    }
                }

                // Draw image
                if (Image != null)
                {
                    if (useVs)
                    {
                        rnd.DrawImage(e.Graphics, iRect, Image);
                    }
                    else
                    {
                        e.Graphics.DrawImage(Image, iRect);
                    }
                }

                // Draw text
                if (Text.Length > 0)
                {
                    var rtl = this.GetRightToLeftProperty();
                    if (useVs)
                    {
                        if (rtl == RightToLeft.Yes)
                        {
                            tff |= TextFormatFlags.RightToLeft;
                        }
                        if (GlowingText)
                        {
                            rnd.DrawGlowingText(e.Graphics, tRect, Text, Font, ForeColor, tff);
                        }
                        else
                        {
                            rnd.DrawText(e.Graphics, tRect, Text, !Enabled, tff);
                        }
                    }
                    else
                    {
                        var br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText;
                        var sf = new StringFormat(StringFormat.GenericDefault);
                        if (rtl == RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }
                        e.Graphics.DrawString(Text, Font, br, ClientRectangle, sf);
                    }
                }
            }
            catch { }
        }