Option Explicit On
Option Strict On
Public Class Form1
Private thePicBox As PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim name As String
For Each name In [Enum].GetNames(GetType(KnownColor))
If Color.FromName(name).IsSystemColor = False Then
If name <> "Transparent" Then
ListBox1.Items.Add(name)
End If
Else
ListBox2.Items.Add(name)
End If
Next 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"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bmp As Bitmap
Dim g As Graphics
Dim dbrush As SolidBrush
Dim ColPen As Pen
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()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim bmp As Bitmap
Dim g As Graphics
Dim dbrush As SolidBrush
Dim ColPen As Pen
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()
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim kpt As Integer = 1
Dim HSIZE As Integer = 88
Dim VSIZE As Integer = 31
Dim bmp As Bitmap
Dim g As Graphics
Dim dbrush As SolidBrush
Dim ColPen As Pen
Dim dir As String = ""
Dim name As String
Dim fnameW As String
Dim sw As System.IO.StreamWriter
Dim colname() As String
Dim pngname() As String
Dim i As Integer
Dim rr As Byte
Dim gg As Byte
Dim bb As Byte
Dim colrgb As String = ""
Dim col16 As String = ""
If folderBrowserDialog1.ShowDialog() = DialogResult.OK Then
dir = FolderBrowserDialog1.SelectedPath
End If
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 To ListBox1.Items.Count - 1
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)
Next i
For i = 0 To ListBox2.Items.Count - 1
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)
Next i
ColPen.Dispose()
g.Dispose()
'htmlファイル出力
ReDim colname(ListBox1.Items.Count + ListBox2.Items.Count - 2)
ReDim pngname(ListBox1.Items.Count + ListBox2.Items.Count - 2)
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 To ListBox1.Items.Count - 1
pngname(i) = "png_col_" + ListBox1.Items(i).ToString() + ".png"
colname(i) = (pngname(i).Replace(".png", "")).Replace("png_col_", "")
Next i
sw.WriteLine("")
sw.WriteLine("")
sw.WriteLine("")
sw.WriteLine("png 画像")
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine("カラーネーム")
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine("16 進表示")
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine("(r, g, b)")
sw.WriteLine(" | ")
sw.WriteLine("
")
For i = 0 To ListBox1.Items.Count - 1
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(colname(i))
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine(col16)
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine(colrgb)
sw.WriteLine(" | ")
sw.WriteLine("
")
Next i
sw.WriteLine("
")
'*******************************************************************
sw.WriteLine("Windows システム色
")
'*******************************************************************
For i = 0 To ListBox2.Items.Count - 1
pngname(i) = "png_col_" + ListBox2.Items(i).ToString() + ".png"
colname(i) = (pngname(i).Replace(".png", "")).Replace("png_col_", "")
Next i
sw.WriteLine("")
sw.WriteLine("")
sw.WriteLine("")
sw.WriteLine("png 画像")
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine("カラーネーム")
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine("16 進表示")
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine("(r, g, b)")
sw.WriteLine(" | ")
sw.WriteLine("
")
For i = 0 To ListBox2.Items.Count - 1
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(colname(i))
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine(col16)
sw.WriteLine(" | ")
sw.WriteLine("")
sw.WriteLine(colrgb)
sw.WriteLine(" | ")
sw.WriteLine("
")
Next i
sw.WriteLine("
")
'*******************************************************************
sw.WriteLine("")
sw.WriteLine("")
sw.Close()
'*******************************************************************
System.Threading.Thread.Sleep(1000) '1秒待つ
System.Diagnostics.Process.Start(fnameW)
End Sub
End Class