⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapes.cs

📁 从设计模式角度介绍了updo redo的实现方法
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace ShapeLib
{
    [Serializable]
    public abstract class Shape
    {
        protected Rectangle bound;
        protected Color color;

        public Rectangle Bound
        {
            get { return bound; }
        }

        public Shape(Color color, Rectangle bound)
        {
            this.bound = bound;
            this.color = color;
        }
        
        public abstract void Paint(Graphics g);
        
    }

    [Serializable]
    public class EllipseShape : Shape
    {
        public EllipseShape(Color color, Rectangle bound)
            : base(color, bound)
        {
        }

        public override void Paint(Graphics g)
        {
            g.FillEllipse(new SolidBrush(color), bound);
        }

    }

    [Serializable]
    public class TriangleShape : Shape
    {
        public TriangleShape(Color color, Rectangle bound)
            : base(color, bound)
        {
        }

        public override void Paint(Graphics g)
        {
            g.FillPolygon(new SolidBrush(color), new Point[] {
                new Point((bound.Left + bound.Right) / 2, bound.Top),
                new Point(bound.Left, bound.Bottom),
                new Point(bound.Right, bound.Bottom) });
        }

    }

    [Serializable]
    public class RectangleShape : Shape
    {
        public RectangleShape(Color color, Rectangle rect)
            : base(color, rect)
        {
        }

        public override void Paint(Graphics g)
        {
            g.FillRectangle(new SolidBrush(color), bound);
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -