www.doronamir.com

E-mail: doron@doronamir.com

 

 

 

 GDI+: PathGradientBrush

שיפור  היישום. : הריבועים ביישום נוצרו בעזרת מברשת משופעת , השינוי חל במתודת Show במחלקה Square

טופס היישום נשאר ללא שינוי ראה בתרגילים הקודמים.

 

 

 

using System;

using System.Drawing;

using System.Drawing.Drawing2D;

namespace DoronAmirGDI_2

{

    public class Square

    {

        private Point sqrLocation;

        private Size sqrSzie;

        private Color ForGroundColor;

        private Color BkGroundColor;

 

        public Square(Size iSize, Color iBackColor, Color iForeColor)

        {

            Size = iSize;

            BackColor = iBackColor;

            ForeColor = iForeColor;

        }

        public Point Location

        {

            get { return sqrLocation; }

            set { sqrLocation = value;  }

        }

 

        public Size Size

        {

            get { return sqrSzie; }

            set { sqrSzie = value;  }

        }

 

        public Color ForeColor

        {

            get { return ForGroundColor;    }

            set { ForGroundColor = value; }

        }

 

        public Color BackColor

        {

            get { return BkGroundColor; }

            set { BkGroundColor = value; }

        }

 

 

        public void Show(System.IntPtr winHandle)

        {

            Graphics GameArea;

            GameArea = Graphics.FromHwnd(winHandle);

 

            GraphicsPath graphPath;

            PathGradientBrush brushSquare;

            Color[] surroundColor;

            Rectangle rectSquare;

 

           

           

            graphPath = new GraphicsPath();

             rectSquare = new Rectangle(Location.X, Location.Y, Size.Width, Size.Height);

            graphPath.AddRectangle(rectSquare);

 

            brushSquare = new PathGradientBrush(graphPath);

            brushSquare.CenterColor = ForeColor;

            surroundColor = new Color[]{BackColor};

            brushSquare.SurroundColors = surroundColor;

 

            GameArea.FillPath(brushSquare, graphPath);

           

        }

 

        public void Hide(System.IntPtr winHandle)

        {

            Graphics GameArea;

            Rectangle CleanerSqr;

            GameArea = Graphics.FromHwnd(winHandle);

             CleanerSqr = new Rectangle(Location.X, Location.Y, Size.Width, Size.Height);

            GameArea.FillRectangle(new SolidBrush(Color.Black), CleanerSqr);

        }

 

       

    }

}