画刷样式管理器

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

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

       public  FromInfo mInfo = new FromInfo();
       private  HatchBrush brush;
       private  Rectangle rectPreview;
       private  Color selectdColor;
       private  HatchStyle hatchStyle;
        private void Form1_Load(object sender, EventArgs e)
        {
        
            foreach (HatchStyle hs in Enum.GetValues(typeof(HatchStyle)))
            {
                comboBox1.Items.Add(hs);

            }
            comboBox1.SelectedIndex = 0;

            foreach (KnownColor color in Enum.GetValues(typeof(System.Drawing.KnownColor)))
            {
                comboBox2.Items.Add(color);

            }
            comboBox2.SelectedIndex = 0;
        }

        private void comboBox2_DrawItem(object sender, DrawItemEventArgs e)
        {
          
            if (e.Index == -1)
            {
                return;
            }

            if (sender == null)
            {
                return;
            }
           
            selectdColor = Color.FromName(this.comboBox2.Items[e.Index].ToString());
            e.DrawBackground();   
            Graphics g = e.Graphics;   
            SolidBrush sbrush = new SolidBrush(selectdColor);
            rectPreview = e.Bounds;
            rectPreview.Offset(1, 1);
            rectPreview.Width = 30;
            g.FillRectangle(sbrush, rectPreview);
            g.DrawString(selectdColor.Name, Font, new SolidBrush(e.ForeColor), e.Bounds.X + 30, e.Bounds.Y + 1);
            e.DrawFocusRectangle();
            sbrush.Dispose();
            g.Dispose();
        }


        private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
        {     
            if (e.Index == -1)
            {
                return;
            }

            if (sender == null)
            {
                return;
            }
            hatchStyle = (HatchStyle)this.comboBox1.Items[e.Index];
            e.DrawBackground();
            Graphics g = e.Graphics;
            HatchBrush mbrush = new HatchBrush(hatchStyle,Color.Black,Color.White);
            rectPreview = e.Bounds;
            rectPreview.Offset(1, 1);
            rectPreview.Width = 30;
            g.FillRectangle(mbrush, rectPreview);
            g.DrawString(hatchStyle.ToString(), Font, new SolidBrush(e.ForeColor), e.Bounds.X + 30, e.Bounds.Y + 1);
            e.DrawFocusRectangle();
            mbrush.Dispose();
            g.Dispose();
          
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            hatchStyle = (HatchStyle)this.comboBox1.SelectedItem; 
            panel1.Refresh();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {     
          
            selectdColor = Color.FromName(this.comboBox2.SelectedItem.ToString());
            panel1.Refresh();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            brush = new HatchBrush(hatchStyle, selectdColor, Color.White);
            g.FillRectangle(brush, 0, 0, panel1.Width, panel1.Height);
            g.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            brush.Dispose();
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
       {
            mInfo.HatchBrush1 = brush;
            brush.Dispose();
            this.Close();
        }
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值