예제 #1
0
        private void form_Resize(object sender, EventArgs e)
        {
            var form = sender as Form;

            if (form != null && (DesktopWindowManager.IsCompositionEnabled() && GetGlassEnabled(form)) || form.IsDesignMode())
            {
                InvalidateNonGlassClientArea(form);
            }
        }
 /// <summary>
 /// Raises the <see cref="E:System.Windows.Forms.Control.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)
 {
     if (!this.IsDesignMode() && SupportGlass && DesktopWindowManager.IsCompositionEnabled())
     {
         try { e.Graphics.Clear(System.Drawing.Color.Black); } catch { }
     }
     else
     {
         if (this.IsDesignMode() || rnd == null || !Application.RenderWithVisualStyles)
         {
             try { e.Graphics.Clear(BackColor); } catch { }
         }
         else
         {
             rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle);
         }
     }
     base.OnPaint(e);
 }
예제 #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);
            }
        }
예제 #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)
        {
            if (Visible)
            {
                VisualStyleRenderer vs = null;
                if (Application.RenderWithVisualStyles || DesktopWindowManager.IsCompositionEnabled())
                {
                    vs = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
                    vs.DrawParentBackground(e.Graphics, base.ClientRectangle, this);
                }

                // Draw image
                Rectangle r = DeflateRect(base.ClientRectangle, base.Padding);
                if (Image != null)
                {
                    //Rectangle ir = CalcImageRenderBounds(this.Image, r, base.RtlTranslateAlignment(this.ImageAlign));
                    if (ImageList != null && ImageIndex == 0)
                    {
                        if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                        {
                            vs.DrawGlassImage(e.Graphics, r, ImageList, ImageIndex);
                        }
                        else
                        {
                            ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, ImageIndex);
                        }
                    }
                    else
                    {
                        if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                        {
                            vs.DrawGlassImage(e.Graphics, r, Image);
                        }
                        else
                        {
                            e.Graphics.DrawImage(Image, r);
                        }
                    }
                }

                // Draw text
                if (Text.Length > 0)
                {
                    if (this.IsDesignMode() || vs == null || !DesktopWindowManager.IsCompositionEnabled())
                    {
                        Brush        br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText;
                        StringFormat sf = new StringFormat(StringFormat.GenericDefault);
                        if (this.GetRightToLeftProperty() == System.Windows.Forms.RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }
                        e.Graphics.DrawString(Text, Font, br, base.ClientRectangle, sf);
                    }
                    else
                    {
                        TextFormatFlags tff = CreateTextFormatFlags(base.RtlTranslateAlignment(TextAlign), AutoEllipsis, UseMnemonic);
                        vs.DrawGlowingText(e.Graphics, base.ClientRectangle, Text, Font, ForeColor, tff);
                    }
                }
            }
        }