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();
}
}
}