//用梯度路径根据以上属性画矩形 public void Show(System.IntPtr WinHandle) { Graphics GameGraphics; GraphicsPath graphPath; PathGradientBrush brushSquare; Color[] surroundColor; Rectangle rectSquare; //获取Graphics对象 GameGraphics = Graphics.FromHwnd(WinHandle); //创建一个由一个矩形构成的路径 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; //根据以上设置画出矩形路径 GameGraphics.FillPath(brushSquare, graphPath); SolidBrush BackColorBrush = new SolidBrush(GameField.BackColor); GameGraphics.FillRectangle(BackColorBrush, new Rectangle(Location, new Size(GameField.SquareRoundCorner, GameField.SquareRoundCorner))); GameGraphics.FillRectangle(BackColorBrush, new Rectangle(Location.X + size.Width - GameField.SquareRoundCorner, Location.Y, GameField.SquareRoundCorner, GameField.SquareRoundCorner)); GameGraphics.FillRectangle(BackColorBrush, new Rectangle(Location.X, Location.Y + size.Height - GameField.SquareRoundCorner, GameField.SquareRoundCorner, GameField.SquareRoundCorner)); GameGraphics.FillRectangle(BackColorBrush, new Rectangle(Location.X + size.Width - GameField.SquareRoundCorner, Location.Y + size.Height - GameField.SquareRoundCorner, GameField.SquareRoundCorner, GameField.SquareRoundCorner)); }
public void Hide(System.IntPtr winHandle) { Graphics GameGraphics; Rectangle rectSquare; // Gets the Graphics object of the background picture GameGraphics = Graphics.FromHwnd(winHandle); // Since we are working in a solid background, we can just draw a solid rectangle in order to "hide" the current square rectSquare = new Rectangle(Location.X, Location.Y, Size.Width, Size.Height); GameGraphics.FillRectangle(new SolidBrush(GameField.BackColor), rectSquare); }
//消去矩形 public void Hide(System.IntPtr WinHandle) { Graphics GameGraphics; Rectangle rectSquare; //获取Graphics对象 GameGraphics = Graphics.FromHwnd(WinHandle); //消去图形 rectSquare = new Rectangle(Location.X, Location.Y, size.Width, size.Height); GameGraphics.FillRectangle(new SolidBrush(GameField.BackColor), rectSquare); }