GDI笔刷

一,solidBrush

纯色填充

利用窗体的paint事件

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush br = new SolidBrush(Color.Red);
            g.FillRectangle(br,10,10,100,100);
            g.Dispose();
         }
Form1_Paint

二,TextureBrush

利用位图填充

首先添加一张图片

using System.IO;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            string path = @"F:LianxiApp1App1Img龙猫.jpg";
            Graphics g = e.Graphics;

            Bitmap img;
            if (File.Exists(path))
            {
                img = new Bitmap(path);
                Brush br = new TextureBrush(img);
                g.FillRectangle(br, 30, 30, 500, 400);
            }
            else
            {
                MessageBox.Show("找不到要填充的图片","提示",MessageBoxButtons.OK);  
            }

            g.Dispose();//释放Graphics所使用的资源
         }
Form1_Paint

 三,LinearGradientBrush

线性渐变

using System.Drawing.Drawing2D;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 140), new Point(280, 140), Color.Red, Color.White);
            g.FillEllipse(lgb, 0, 140, 280, 120);
            lgb.Dispose();
            g.Dispose();
        }
Form1_Paint

四,PathGradientBrush 

中心点渐变

using System.Drawing.Drawing2D;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddEllipse(0, 80, 280, 120);
            PathGradientBrush pgb = new PathGradientBrush(gp);
            pgb.CenterColor = Color.FromArgb(0, 255, 255, 20);
            Color[] colors = { Color.FromArgb(255, 0, 255, 0)};//FromArgb(透明度,R,G,B)
            pgb.SurroundColors = colors;
            e.Graphics.FillEllipse(pgb, 0, 80, 280, 120);
            pgb.Dispose();
        }
Form1_Paint

五,HatchBrush

以条案填充

using System.Drawing.Drawing2D;
       private void Form1_Paint(object sender, PaintEventArgs e)
        {
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.HorizontalBrick,Color.White,Color.Red);
            e.Graphics.FillRectangle(hatchBrush,10,10,100,100);
            e.Graphics.Dispose();
        }
Form1_Paint
原文地址:https://www.cnblogs.com/Luck1996/p/11976802.html