예제 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);

            ThemeManager.PrepareGraphics(e.Graphics);

            Color c1    = GetBackColor();
            Color cText = Enabled ? GetForeColor() : Color.FromKnownColor(KnownColor.ControlDark);

            Rectangle rc = ClientRectangle;

            rc.Inflate(2, 2);

            using (Brush b = new SolidBrush(c1))
            {
                e.Graphics.FillRectangle(b, rc);
            }

            if (Image != null)
            {
                Point p = new Point(2 + rc.Location.X, rc.Location.Y + (this.Height - Image.Height) / 2);
                e.Graphics.DrawImageUnscaled(Image, p);

                rc.Offset(Image.Width + 5, 0);
            }

            using (Brush b = new SolidBrush(cText))
            {
                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignments.FromContentAlignment(TextAlign).Alignment;
                sf.LineAlignment = StringAlignments.FromContentAlignment(TextAlign).LineAlignment;

                if (base.AutoSize)
                {
                    sf.Trimming    = StringTrimming.None;
                    sf.FormatFlags = StringFormatFlags.NoWrap;
                }
                else
                {
                    sf.Trimming = StringTrimming.EllipsisWord;
                }

                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

                if (this.VerticalText)
                {
                    sf.FormatFlags |= StringFormatFlags.DirectionVertical;
                    try
                    {
                        e.Graphics.RotateTransform(180);
                        e.Graphics.TranslateTransform(-Width, -Height);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                e.Graphics.DrawString(this.Text, this.Font, b, rc, sf);
            }
        }
예제 #2
0
        void OPMCheckBox_Paint(object sender, PaintEventArgs e)
        {
            ThemeManager.PrepareGraphics(e.Graphics);

            int   pw = 1;
            Color c1 = Color.Empty, c2 = Color.Empty, cb = Color.Empty, cText = Color.Empty;

            c1    = Enabled ? ThemeManager.GradientNormalColor1 : ThemeManager.BackColor;
            cb    = Enabled ? ThemeManager.BorderColor : ThemeManager.GradientNormalColor2;
            cText = Enabled ? ThemeManager.ForeColor : Color.FromKnownColor(KnownColor.ControlDark);

            if (Enabled && (_isHovered || Focused))
            {
                if (_isHovered && Focused)
                {
                    c1 = ThemeManager.GradientFocusHoverColor1;
                    cb = ThemeManager.FocusBorderColor;
                    //pw = 2;
                }
                else if (Focused)
                {
                    c1 = ThemeManager.GradientFocusColor1;
                    cb = ThemeManager.FocusBorderColor;
                    //pw = 2;
                }
                else
                {
                    c1 = ThemeManager.GradientHoverColor1;
                }
            }

            Rectangle rcFill = new Rectangle(-1, 0, Width + 1, Height);

            using (Brush b = new SolidBrush(ThemeManager.BackColor))
            {
                e.Graphics.FillRectangle(b, rcFill);
            }

            ButtonState bs = Checked ? ButtonState.Checked : ButtonState.Normal;

            bs |= ButtonState.Flat;

            // Get the size of the checkbox glyph (depending on OS settings this may vary)
            Size sz = CheckBoxRenderer.GetGlyphSize(e.Graphics, CheckBoxState.UncheckedNormal);

            sz = new System.Drawing.Size(sz.Width, sz.Height);


            int glyphTop = (CheckAlign == System.Drawing.ContentAlignment.TopLeft) ? 2 : (Height - sz.Height) / 2;

            Rectangle rcGlyph = new Rectangle(1, glyphTop, sz.Width - 2, sz.Height - 2);
            Rectangle rcCheck = new Rectangle(rcGlyph.Left + 2, rcGlyph.Top + 2, rcGlyph.Width - 4, rcGlyph.Width - 4);

            Rectangle rcText = new Rectangle(rcGlyph.Right + 5, 0, Width - rcGlyph.Width - 5,
                                             Height);

            int d = 2 * rcCheck.Width / 3;

            using (Brush b = new SolidBrush(c1))
                using (Pen p = new Pen(cb, pw))
                {
                    e.Graphics.FillRectangle(b, rcGlyph);
                    e.Graphics.DrawRectangle(p, rcGlyph);
                }

            using (Brush b = new SolidBrush(cText))
                using (Pen p = new Pen(b, 2))
                {
                    switch (CheckState)
                    {
                    case CheckState.Checked:
                        e.Graphics.DrawLine(p, rcCheck.Left, rcCheck.Top + d, rcCheck.Right - d, rcCheck.Bottom);
                        e.Graphics.DrawLine(p, rcCheck.Right - d, rcCheck.Bottom, rcCheck.Right, rcCheck.Top);
                        break;

                    case CheckState.Indeterminate:
                        e.Graphics.FillRectangle(b, rcCheck);
                        break;
                    }
                }

            using (Brush b = new SolidBrush(cText))
            {
                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignments.FromContentAlignment(TextAlign).Alignment;
                sf.LineAlignment = StringAlignments.FromContentAlignment(TextAlign).LineAlignment;
                sf.Trimming      = StringTrimming.EllipsisWord;
                //sf.FormatFlags = StringFormatFlags.NoWrap;
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

                e.Graphics.DrawString(this.Text, this.Font, b, rcText, sf);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            using (SmoothGraphics sg = SmoothGraphics.New(e.Graphics, this.ClientRectangle))
            {
                int   pw = 1;
                Color c1 = Color.Empty, c2 = Color.Empty, cb = Color.Empty, cText = Color.Empty;

                c1    = Enabled ? ThemeManager.GradientNormalColor1 : ThemeManager.BackColor;
                c2    = Enabled ? ThemeManager.GradientNormalColor2 : ThemeManager.BackColor;
                cb    = Enabled ? ThemeManager.BorderColor : ThemeManager.GradientNormalColor2;
                cText = Enabled ? ThemeManager.ForeColor : Color.FromKnownColor(KnownColor.ControlDark);

                if (Enabled && (_isHovered || Focused))
                {
                    if (_isHovered && Focused)
                    {
                        c1 = ThemeManager.GradientFocusHoverColor1;
                        c2 = ThemeManager.GradientFocusHoverColor2;
                        cb = ThemeManager.FocusBorderColor;
                        //pw = 2;
                    }
                    else if (Focused)
                    {
                        c1 = ThemeManager.GradientFocusColor1;
                        c2 = ThemeManager.GradientFocusColor2;
                        cb = ThemeManager.FocusBorderColor;
                        //pw = 2;
                    }
                    else
                    {
                        c1    = ThemeManager.GradientHoverColor1;
                        c2    = ThemeManager.GradientHoverColor2;
                        cText = ThemeManager.SelectedTextColor;
                    }
                }

                if (_overrideBackColor != Color.Empty)
                {
                    c1 = c2 = _overrideBackColor;
                }
                if (_overrideForeColor != Color.Empty)
                {
                    cText = _overrideForeColor;
                }

                Rectangle rcb = ClientRectangle;
                rcb.Inflate(1, 1);

                using (Brush b = new SolidBrush(ThemeManager.BackColor))
                    using (Pen p = new Pen(b, 4))
                    {
                        sg.Graphics.FillRectangle(b, rcb);
                    }

                Rectangle rc = ClientRectangle;

                if (_isMouseDown || _isKeyDown)
                {
                    rc = new Rectangle(2, 2, Width - 4, Height - 4);
                }
                else
                {
                    rc = new Rectangle(1, 1, Width - 2, Height - 2);
                }

                using (Brush b = new LinearGradientBrush(rc, c1, c2, 90f))
                    using (Pen p = new Pen(cb, pw))
                    {
                        sg.Graphics.FillRectangle(b, rc);
                        sg.Graphics.DrawRectangle(p, rc);
                    }

                if (this.Image != null)
                {
                    rc = ClientRectangle;

                    Rectangle rcImage = new Rectangle(
                        (rc.Size.Width - Image.Size.Width) / 2,
                        (rc.Size.Height - Image.Size.Height) / 2,
                        rc.Size.Width, rc.Size.Height);

                    int l = rcImage.Left;
                    int t = rcImage.Top;
                    rcImage.Location = new Point(l, t);

                    int w = Math.Min(Image.Width, rcImage.Size.Width);
                    int h = Math.Min(Image.Height, rcImage.Size.Height);
                    rcImage.Size = new System.Drawing.Size(w, h);

                    sg.Graphics.DrawImage(Image, rcImage);
                }
                else
                {
                    using (Brush b = new SolidBrush(cText))
                    {
                        StringFormat sf = new StringFormat();
                        sf.Alignment     = StringAlignments.FromContentAlignment(TextAlign).Alignment;
                        sf.LineAlignment = StringAlignments.FromContentAlignment(TextAlign).LineAlignment;
                        sf.Trimming      = StringTrimming.EllipsisWord;
                        //sf.FormatFlags = StringFormatFlags.NoWrap;

                        sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

                        Rectangle rcText = rc;
                        if (ShowDropDown)
                        {
                            rcText = new Rectangle(0, 0, this.Width - ArrowSize, this.Height);
                        }

                        sg.Graphics.DrawString(this.Text, this.Font, b, rcText, sf);
                    }

                    if (ShowDropDown)
                    {
                        Rectangle rcArrow = new Rectangle(this.Width - ArrowSize, 0, ArrowSize, this.Height);
                        using (GraphicsPath gp = ImageProcessing.GenerateCenteredArrow(rcArrow))
                            using (Brush b = new SolidBrush(cText))
                                using (Pen p = new Pen(b, 1))
                                {
                                    sg.Graphics.FillPath(b, gp);
                                    sg.Graphics.DrawPath(p, gp);

                                    Point p1 = new Point(this.Width - ArrowSize + 2, 2);
                                    Point p2 = new Point(this.Width - ArrowSize + 2, this.Height - 4);
                                    sg.Graphics.DrawLine(p, p1, p2);
                                }
                    }
                }
            }
        }