コード例 #1
0
        public static void DrawBorder(BorderStyle2 Style, Color BorderColor, Graphics g, Rectangle r)
        {
            switch (Style) {
                case BorderStyle2.Dotted: {
                    r.Width --;
                    r.Height --;
                    g.DrawRectangle(new Pen(SystemColors.Control), r);
                    var p = new Pen(BorderColor) {DashStyle = DashStyle.Dot};
                    g.DrawRectangle(p, r);
                    break;
                }
                case BorderStyle2.Dashed: {
                    r.Width --;
                    r.Height --;
                    g.DrawRectangle(new Pen(SystemColors.Control), r);
                    var p = new Pen(BorderColor) {DashStyle = DashStyle.Dash};
                    g.DrawRectangle(p, r);

                    break;
                }
                case BorderStyle2.Sunken: {
                    if (BorderColor == Color.Black) {
                        BorderColor = SystemColors.Control;
                    }
                    //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Sunken);
                    DrawBorder(Border3DStyle.Sunken, BorderColor, g, r);
                    break;
                }
                case BorderStyle2.FixedSingle: {
                    r.Width --;
                    r.Height --;
                    g.DrawRectangle(new Pen(BorderColor), r);
                    break;
                }
                case BorderStyle2.FixedDouble: {
                    g.DrawRectangle(new Pen(BorderColor), r.Left, r.Top, r.Width - 1, r.Height - 1);
                    g.DrawRectangle(new Pen(BorderColor), r.Left + 1, r.Top + 1, r.Width - 3, r.Height - 3);
                    break;
                }
                case BorderStyle2.Raised: {
                    if (BorderColor == Color.Black) {
                        BorderColor = SystemColors.Control;
                    }

                    DrawBorder(Border3DStyle.Raised, BorderColor, g, r);
                    //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Raised);
                    break;
                }
                case BorderStyle2.RaisedThin: {
                    if (BorderColor == Color.Black) {
                        BorderColor = Color.FromArgb(SystemColors.Control.R, SystemColors.Control.G,
                                                     SystemColors.Control.B);
                    }

                    DrawBorder(Border3DStyle.RaisedInner, BorderColor, g, r);
                    //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Raised);
                    break;
                }
                case BorderStyle2.SunkenThin: {
                    if (BorderColor == Color.Black) {
                        BorderColor = Color.FromArgb(SystemColors.Control.R, SystemColors.Control.G,
                                                     SystemColors.Control.B);
                    }

                    DrawBorder(Border3DStyle.SunkenOuter, BorderColor, g, r);
                    //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Raised);
                    break;
                }
                case BorderStyle2.Etched: {
                    ControlPaint.DrawBorder3D(g, r, Border3DStyle.Etched);

                    break;
                }
                case BorderStyle2.Bump: {
                    if (BorderColor == Color.Black) {
                        BorderColor = SystemColors.Control;
                    }

                    var b = new SolidBrush(BorderColor);
                    g.FillRectangle(b, r.Left, r.Top, r.Width, 4);
                    g.FillRectangle(b, r.Left, r.Bottom - 4, r.Width, 4);

                    g.FillRectangle(b, r.Left, r.Top, 4, r.Height);
                    g.FillRectangle(b, r.Right - 4, r.Top, 4, r.Height);
                    b.Dispose();

                    DrawBorder(Border3DStyle.Raised, BorderColor, g, r);
                    DrawBorder(Border3DStyle.Sunken, BorderColor, g,
                               new Rectangle(r.Left + 4, r.Top + 4, r.Width - 8, r.Height - 8));
                    break;
                }
                case BorderStyle2.Column: {
                    var light = new SolidBrush(MixColors(BorderColor, Color.White, 1));
                    var dark = new SolidBrush(MixColors(BorderColor, Color.Black, 0.4));

                    g.FillRectangle(light, r.Left, r.Top, r.Width, 1);
                    g.FillRectangle(light, r.Left, r.Top + 3, 1, r.Height - 1 - 6);
                    g.FillRectangle(dark, r.Right - 1, r.Top + 3, 1, r.Height - 6);
                    g.FillRectangle(dark, r.Left, r.Bottom - 1, r.Width, 1);
                    break;
                }
                case BorderStyle2.Row: {
                    var light = new SolidBrush(MixColors(BorderColor, Color.White, 1));
                    var dark = new SolidBrush(MixColors(BorderColor, Color.Black, 0.4));

                    g.FillRectangle(light, r.Left + 3, r.Top, r.Width - 6, 1);
                    g.FillRectangle(light, r.Left, r.Top, 1, r.Height - 1);
                    g.FillRectangle(dark, r.Right - 1, r.Top, 1, r.Height);
                    g.FillRectangle(dark, r.Left + 3, r.Bottom - 1, r.Width - 6, 1);
                    break;
                }
            }
        }
コード例 #2
0
        public static void DrawBorder(BorderStyle2 Style, Color BorderColor, Graphics g, Rectangle r)
        {
            switch (Style)
            {
            case BorderStyle2.Dotted:
            {
                r.Width--;
                r.Height--;
                g.DrawRectangle(new Pen(SystemColors.Control), r);
                var p = new Pen(BorderColor)
                {
                    DashStyle = DashStyle.Dot
                };
                g.DrawRectangle(p, r);
                break;
            }

            case BorderStyle2.Dashed:
            {
                r.Width--;
                r.Height--;
                g.DrawRectangle(new Pen(SystemColors.Control), r);
                var p = new Pen(BorderColor)
                {
                    DashStyle = DashStyle.Dash
                };
                g.DrawRectangle(p, r);

                break;
            }

            case BorderStyle2.Sunken:
            {
                if (BorderColor == Color.Black)
                {
                    BorderColor = SystemColors.Control;
                }
                //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Sunken);
                DrawBorder(Border3DStyle.Sunken, BorderColor, g, r);
                break;
            }

            case BorderStyle2.FixedSingle:
            {
                r.Width--;
                r.Height--;
                g.DrawRectangle(new Pen(BorderColor), r);
                break;
            }

            case BorderStyle2.FixedDouble:
            {
                g.DrawRectangle(new Pen(BorderColor), r.Left, r.Top, r.Width - 1, r.Height - 1);
                g.DrawRectangle(new Pen(BorderColor), r.Left + 1, r.Top + 1, r.Width - 3, r.Height - 3);
                break;
            }

            case BorderStyle2.Raised:
            {
                if (BorderColor == Color.Black)
                {
                    BorderColor = SystemColors.Control;
                }

                DrawBorder(Border3DStyle.Raised, BorderColor, g, r);
                //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Raised);
                break;
            }

            case BorderStyle2.RaisedThin:
            {
                if (BorderColor == Color.Black)
                {
                    BorderColor = Color.FromArgb(SystemColors.Control.R, SystemColors.Control.G,
                                                 SystemColors.Control.B);
                }

                DrawBorder(Border3DStyle.RaisedInner, BorderColor, g, r);
                //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Raised);
                break;
            }

            case BorderStyle2.SunkenThin:
            {
                if (BorderColor == Color.Black)
                {
                    BorderColor = Color.FromArgb(SystemColors.Control.R, SystemColors.Control.G,
                                                 SystemColors.Control.B);
                }

                DrawBorder(Border3DStyle.SunkenOuter, BorderColor, g, r);
                //System.Windows.Forms.ControlPaint.DrawBorder3D (g,r,Border3DStyle.Raised);
                break;
            }

            case BorderStyle2.Etched:
            {
                ControlPaint.DrawBorder3D(g, r, Border3DStyle.Etched);

                break;
            }

            case BorderStyle2.Bump:
            {
                if (BorderColor == Color.Black)
                {
                    BorderColor = SystemColors.Control;
                }

                var b = new SolidBrush(BorderColor);
                g.FillRectangle(b, r.Left, r.Top, r.Width, 4);
                g.FillRectangle(b, r.Left, r.Bottom - 4, r.Width, 4);

                g.FillRectangle(b, r.Left, r.Top, 4, r.Height);
                g.FillRectangle(b, r.Right - 4, r.Top, 4, r.Height);
                b.Dispose();

                DrawBorder(Border3DStyle.Raised, BorderColor, g, r);
                DrawBorder(Border3DStyle.Sunken, BorderColor, g,
                           new Rectangle(r.Left + 4, r.Top + 4, r.Width - 8, r.Height - 8));
                break;
            }

            case BorderStyle2.Column:
            {
                var light = new SolidBrush(MixColors(BorderColor, Color.White, 1));
                var dark  = new SolidBrush(MixColors(BorderColor, Color.Black, 0.4));

                g.FillRectangle(light, r.Left, r.Top, r.Width, 1);
                g.FillRectangle(light, r.Left, r.Top + 3, 1, r.Height - 1 - 6);
                g.FillRectangle(dark, r.Right - 1, r.Top + 3, 1, r.Height - 6);
                g.FillRectangle(dark, r.Left, r.Bottom - 1, r.Width, 1);
                break;
            }

            case BorderStyle2.Row:
            {
                var light = new SolidBrush(MixColors(BorderColor, Color.White, 1));
                var dark  = new SolidBrush(MixColors(BorderColor, Color.Black, 0.4));

                g.FillRectangle(light, r.Left + 3, r.Top, r.Width - 6, 1);
                g.FillRectangle(light, r.Left, r.Top, 1, r.Height - 1);
                g.FillRectangle(dark, r.Right - 1, r.Top, 1, r.Height);
                g.FillRectangle(dark, r.Left + 3, r.Bottom - 1, r.Width - 6, 1);
                break;
            }
            }
        }