Пример #1
0
        /// <summary>
        /// </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 (this.Image != null)
                //{
                //    //Rectangle ir = CalcImageRenderBounds(this.Image, r, base.RtlTranslateAlignment(this.ImageAlign));
                //    if (this.ImageList != null && this.ImageIndex == 0)
                //    {
                //        if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                //            vs.DrawGlassIcon(e.Graphics, r, this.ImageList, this.ImageIndex);
                //        else
                //            this.ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, this.ImageIndex);
                //    }
                //    else
                //    {
                //        if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                //            vs.DrawGlassImage(e.Graphics, r, this.Image);
                //        else
                //            e.Graphics.DrawImage(this.Image, r);
                //    }
                //}

                // Draw text
                if (this.Text.Length > 0)
                {
                    if (this.IsDesignMode() || vs == null || !DesktopWindowManager.IsCompositionEnabled())
                    { //DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText :
                        Brush        br = new SolidBrush(Color.FromArgb(255, 1, 163, 215));
                        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(this.TextAlign), this.AutoEllipsis, this.UseMnemonic);
                        vs.DrawGlowingText(e.Graphics, base.ClientRectangle, Text, Font, ForeColor, tff);
                    }
                }
            }
        }
Пример #2
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 { }
        }