[카테고리:] <span>Window Forms [C#]</span>

안녕하세요. 언제나휴일입니다.

Brush는 영역을 채울 때 사용합니다.

속이 꽉 찬 SolidBrush, 특정 패턴의 HatchBrush, 특정 이미지를 패턴으로 하는 TextureBrush 등이 있습니다.

같이 작성해 보고 Look & Feel 해 보세요.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace 브러시_종류
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            Font font = new Font("고딕", 12, FontStyle.Bold);

            for (int h = 0; h <= 52; h++)
            {
                
                HatchStyle hs = (HatchStyle)h;
                Brush hb = new HatchBrush(hs, Color.White);
                graphics.FillRectangle(hb, new Rectangle((h/26)*250, (h%26)*20, 50, 20));
                graphics.DrawString(hs.ToString(), font, Brushes.DarkGreen, (h/26)*250+50, (h%26)*20);
            }

            Brush brush = new SolidBrush(Color.Green);
            graphics.FillRectangle(brush, new Rectangle(500, 20, 50, 20));
            graphics.DrawString("SolidBrush - Green", font, Brushes.Green, 550, 20);

            Image image = new Bitmap(10, 10);
            Graphics ig = Graphics.FromImage(image);
            ig.FillRectangle(Brushes.Black, new Rectangle(0, 0, 5, 5));
            ig.FillRectangle(Brushes.Blue, new Rectangle(5, 0, 5, 5));
            ig.FillRectangle(Brushes.Red, new Rectangle(0, 5, 5, 5));
            ig.FillRectangle(Brushes.Green, new Rectangle(5, 5, 5, 5));
            image.Save("myimage.bmp");

            Brush tb = new TextureBrush(image);
            graphics.FillRectangle(tb, new Rectangle(500, 40, 50, 20));
            graphics.DrawString("TextureBrush - myimage", font, Brushes.Green, 550, 40);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Size = new Size(1000, 600);
        }
    }
}
실행 화면
실행 화면

Window Forms [C#]