• 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
  • 相关阅读:
    Tomcat 配置用户认证服务供C#客户端调用
    Solr与HBase架构设计
    一个自定义MVP .net框架 AngelFrame
    Dell R720上的系统安装问题的解决办法(关于RAID建立磁盘阵列的技术)
    中文分词器性能比较
    关于RabbitMQ关键性问题的总结
    js基本类型与引用类型,浅拷贝和深拷贝
    sass初学入门笔记(一)
    Emmet插件比较实用常用的写法
    今天发现新大陆:haml和Emmet
  • 原文地址:https://www.cnblogs.com/Luck1996/p/11976802.html
Copyright © 2020-2023  润新知