// Draws a rectangle with gradient path using the properties above public void Show(System.IntPtr winHandle) { // If we wish to draw a simple solid triangle with a coloured border, we can use: // GameGraphics.FillRectangle(New SolidBrush(ForeColor), Location.X, Location.Y, Size.Width, Size.Height) // GameGraphics.FillRectangle(New SolidBrush(BackColor), Location.X + 1, Location.Y + 1, Size.Width - 2, Size.Height - 2) Graphics GameGraphics; GraphicsPath graphPath; PathGradientBrush brushSquare; Color[] surroundColor; Rectangle rectSquare; // Gets the Graphics object of the background picture GameGraphics = Graphics.FromHwnd(winHandle); // Create a path consisting of one rectangle graphPath = new GraphicsPath(); rectSquare = new Rectangle(Location.X, Location.Y, Size.Width, Size.Height); graphPath.AddRectangle(rectSquare); // Creates the gradient brush which will draw the square // Note: Theres one center color and an array of border colors brushSquare = new PathGradientBrush(graphPath); brushSquare.CenterColor = ForeColor; surroundColor = new Color[] { BackColor }; brushSquare.SurroundColors = surroundColor; // Finally draws the square GameGraphics.FillPath(brushSquare, graphPath); }
//用梯度路径根据以上属性画矩形 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 MonoColorShow(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[] { ForeColor }; brushSquare.SurroundColors = surroundColor; //根据以上设置画出矩形路径 GameGraphics.FillPath(brushSquare, graphPath); }
public void HideToDelete(System.IntPtr WinHandle) { Graphics GameGraphics; Rectangle rectSquare; GraphicsPath graphPath; PathGradientBrush brushSquare; Color[] surroundColor; DrawFrame(WinHandle); //获取Graphics对象 GameGraphics = Graphics.FromHwnd(WinHandle); rectSquare = new Rectangle(Location.X, Location.Y, size.Width, size.Height); graphPath = new GraphicsPath(); graphPath.AddRectangle(rectSquare); //创建用于画矩形的路径画刷 brushSquare = new PathGradientBrush(graphPath); brushSquare.CenterColor = Color.FromArgb(133, 129, 166); surroundColor = new Color[] { Color.FromArgb(37, 36, 52) }; brushSquare.SurroundColors = surroundColor; //根据以上设置画出矩形路径 GameGraphics.FillPath(brushSquare, graphPath); }