c#的HatchBrush绘制特定样式矩形图案

代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;//加上这个命名空间


namespace WindowsFormsApp7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            //在容器Panel控件的Paint事件中,创建Graphics类的对象g
            Graphics g = e.Graphics;
            //创建HatchBrush类,设置HatchStyle值,前景色及背景色
            HatchBrush h = new HatchBrush(HatchStyle.Vertical,
                Color.Red, Color.Black);
            //绘制矩形
            Rectangle r = new Rectangle(10,10,300,200);
            g.FillRectangle(h, r);
        }
    }
}

结果

AfterRun.PNG

你可能感兴趣的:(c#的HatchBrush绘制特定样式矩形图案)