zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    XSS跨站脚本攻击在Java开发中防范的方法
    Nginx 安装成 Windows 服务
    Nginx配置文件详细说明
    Hadoop是什么
    ORACLE解决登陆em状态暂挂方法
    五月最新图标资源合集!1000+线性图标免费下载(已打包)
    Messages.pas里的消息
    解决DataSnap支持的Tcp长连接数受限的两种方法
    Delphi 两个应用程序(进程)之间的通信
    解决DataSnap支持的Tcp长连接数受限的两种方法
  • 原文地址:https://www.cnblogs.com/Luck1996/p/11976802.html
Copyright © 2011-2022 走看看