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; namespace vcsCOLOR { public partial class Form1 : Form { PictureBox thePicBox; public Form1() { InitializeComponent(); } //------------------------------------------------------------------------- private void Form1_Load(object sender, EventArgs e) { foreach (string name in Enum.GetNames(typeof(KnownColor))) { if (Color.FromName(name).IsSystemColor == false) { if (name != "Transparent") { listBox1.Items.Add(name); } } else { listBox2.Items.Add(name); } } listBox1.SelectedIndex = 0; listBox2.SelectedIndex = 0; pictureBox1.Visible = true; pictureBox2.Visible = true; pictureBox3.Visible = false; label1.Text = "カラーネーム 140色"; label2.Text = "Windows システム色"; button1.Text = "Draw"; button2.Text = "Draw"; } //------------------------------------------------------------------------- private void button1_Click(object sender, EventArgs e) { Bitmap bmp; Graphics g; SolidBrush dbrush; Pen ColPen; thePicBox = pictureBox1; bmp = new Bitmap(thePicBox.Width, thePicBox.Height); thePicBox.Image = bmp; g = Graphics.FromImage(thePicBox.Image); ColPen = new Pen(Color.FromName("Black")); ColPen.Width = 2; dbrush = new SolidBrush(Color.FromName(listBox1.SelectedItem.ToString())); g.FillRectangle(dbrush, new Rectangle(0, 0, thePicBox.Width, thePicBox.Height)); g.DrawRectangle(ColPen, new Rectangle(0, 0, thePicBox.Width, thePicBox.Height)); dbrush.Dispose(); ColPen.Dispose(); g.Dispose(); } //------------------------------------------------------------------------- private void button2_Click(object sender, EventArgs e) { Bitmap bmp; Graphics g; SolidBrush dbrush; Pen ColPen; thePicBox = pictureBox2; bmp = new Bitmap(thePicBox.Width, thePicBox.Height); thePicBox.Image = bmp; g = Graphics.FromImage(thePicBox.Image); ColPen = new Pen(Color.FromName("Black")); ColPen.Width = 2; dbrush = new SolidBrush(Color.FromName(listBox2.SelectedItem.ToString())); g.FillRectangle(dbrush, new Rectangle(0, 0, thePicBox.Width, thePicBox.Height)); g.DrawRectangle(ColPen, new Rectangle(0, 0, thePicBox.Width, thePicBox.Height)); dbrush.Dispose(); ColPen.Dispose(); g.Dispose(); } //------------------------------------------------------------------------- private void toolStripButton1_Click(object sender, EventArgs e) { int kpt = 1; int HSIZE = 88; int VSIZE = 31; Bitmap bmp; Graphics g; string dir = ""; SolidBrush dbrush; Pen ColPen; int i; string name; string fnameW; byte rr, gg, bb; string colrgb = ""; string col16 = ""; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { dir = folderBrowserDialog1.SelectedPath; } thePicBox = pictureBox3; thePicBox.Size = new Size(kpt * HSIZE, kpt * VSIZE); bmp = new Bitmap(kpt * thePicBox.Width, kpt * thePicBox.Height); thePicBox.Image = bmp; g = Graphics.FromImage(thePicBox.Image); ColPen = new Pen(Brushes.Black); ColPen.Width = 2; for (i = 0; i <= listBox1.Items.Count - 1; i++) { name = listBox1.Items[i].ToString(); Console.WriteLine(name); dbrush = new SolidBrush(Color.FromName(name)); g.FillRectangle(dbrush, new Rectangle(0, 0, kpt * HSIZE, kpt * VSIZE)); g.DrawRectangle(ColPen, new Rectangle(0, 0, kpt * HSIZE, kpt * VSIZE)); dbrush.Dispose(); fnameW = dir + "\\png_col_" + name + ".png"; thePicBox.Image.Save(fnameW, System.Drawing.Imaging.ImageFormat.Png); } for (i = 0; i <= listBox2.Items.Count - 1; i++) { name = listBox2.Items[i].ToString(); Console.WriteLine(name); dbrush = new SolidBrush(Color.FromName(name)); g.FillRectangle(dbrush, new Rectangle(0, 0, kpt * HSIZE, kpt * VSIZE)); g.DrawRectangle(ColPen, new Rectangle(0, 0, kpt * HSIZE, kpt * VSIZE)); dbrush.Dispose(); fnameW = dir + "\\png_col_" + name + ".png"; thePicBox.Image.Save(fnameW, System.Drawing.Imaging.ImageFormat.Png); } ColPen.Dispose(); g.Dispose(); //htmlファイル出力 System.IO.StreamWriter sw; string[] colname = new string[listBox1.Items.Count + listBox2.Items.Count]; string[] pngname = new string[listBox1.Items.Count + listBox2.Items.Count]; fnameW = dir + "\\subPNGcolor.html"; sw = new System.IO.StreamWriter(fnameW, false, System.Text.Encoding.GetEncoding("shift-jis")); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine("

VB & C# Color

"); //******************************************************************* sw.WriteLine("

カラーネーム 140 色

"); for (i = 0; i <= listBox1.Items.Count - 1; i++) { pngname[i] = "png_col_"+listBox1.Items[i].ToString()+".png"; colname[i] = (pngname[i].Replace(".png", "")).Replace("png_col_", ""); } sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); for (i = 0; i <= listBox1.Items.Count-1; i++) { rr = Color.FromName(colname[i]).R; gg = Color.FromName(colname[i]).G; bb = Color.FromName(colname[i]).B; colrgb = "(" + rr.ToString() + "," + gg.ToString() + "," + bb.ToString() + ")"; col16 = "#" + rr.ToString("X2") + gg.ToString("X2") + bb.ToString("X2"); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); } sw.WriteLine("
"); sw.WriteLine("png 画像"); sw.WriteLine(""); sw.WriteLine("カラーネーム"); sw.WriteLine(""); sw.WriteLine("16 進表示"); sw.WriteLine(""); sw.WriteLine("(r, g, b)"); sw.WriteLine("
"); sw.WriteLine("\"""); sw.WriteLine(""); sw.WriteLine(colname[i]); sw.WriteLine(""); sw.WriteLine(col16); sw.WriteLine(""); sw.WriteLine(colrgb); sw.WriteLine("
"); //******************************************************************* sw.WriteLine("

Windows システム色

"); for (i = 0; i <= listBox2.Items.Count - 1; i++) { pngname[i] = "png_col_" + listBox2.Items[i].ToString() + ".png"; colname[i] = (pngname[i].Replace(".png", "")).Replace("png_col_", ""); } sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); for (i = 0; i <= listBox2.Items.Count - 1; i++) { rr = Color.FromName(colname[i]).R; gg = Color.FromName(colname[i]).G; bb = Color.FromName(colname[i]).B; colrgb = "(" + rr.ToString() + "," + gg.ToString() + "," + bb.ToString() + ")"; col16 = "#" + rr.ToString("X2") + gg.ToString("X2") + bb.ToString("X2"); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); sw.WriteLine(""); } sw.WriteLine("
"); sw.WriteLine("png 画像"); sw.WriteLine(""); sw.WriteLine("カラーネーム"); sw.WriteLine(""); sw.WriteLine("16 進表示"); sw.WriteLine(""); sw.WriteLine("(r, g, b)"); sw.WriteLine("
"); sw.WriteLine("\"""); sw.WriteLine(""); sw.WriteLine(colname[i]); sw.WriteLine(""); sw.WriteLine(col16); sw.WriteLine(""); sw.WriteLine(colrgb); sw.WriteLine("
"); //******************************************************************* sw.WriteLine(""); sw.WriteLine(""); sw.Close(); //******************************************************************* System.Threading.Thread.Sleep(1000); //1秒待つ System.Diagnostics.Process.Start(fnameW); } //------------------------------------------------------------------------- } }