Option Explicit On
Option Strict On
Public Class Form1
Private dir As String = "c:\vb2010pro\vb7WEBcolor140\data-file"
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim sr As System.IO.StreamReader
Dim sw As System.IO.StreamWriter
Dim dat As String
Dim sbuf() As String
Dim delim() As Char = {","c}
Dim fnameR As String
Dim fnameW1 As String
Dim fnameW2 As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim colname(139) As String
Dim rr As Byte
Dim gg As Byte
Dim bb As Byte
Dim colrgb As String = ""
Dim col_16 As String = ""
Dim strcol As String = ""
Dim num As Integer
Dim ic As Integer
'Dim scase As String = "_16"
Dim scase As String = "rgb"
fnameW1 = dir & "\subwebcolor140" & scase & ".html"
fnameW2 = dir & "\cswebcolor140" & scase & ".css"
ToolStripLabel1.Text = fnameW1
'htmlファイル出力
sw = New System.IO.StreamWriter(fnameW1, False, System.Text.Encoding.GetEncoding("shift-jis"))
sw.WriteLine("")
sw.WriteLine("
")
sw.WriteLine("")
sw.WriteLine("")
sw.WriteLine("")
'*******************************************************************
fnameR = dir & "\inpvbcolorname.txt"
'ColorプロパティのTransparentはrgb値が(255,255,255)でWhiteと同じため省略
sr = New System.IO.StreamReader(fnameR, System.Text.Encoding.GetEncoding("shift-jis"))
k = 0
Do While sr.Peek() >= 0
dat = sr.ReadLine() : sbuf = dat.Split(delim)
colname(k) = sbuf(0)
k = k + 1
Loop
sr.Close()
sw.WriteLine("
")
'*******************************************************************
sw.WriteLine("")
sw.WriteLine("")
sw.Close()
'*******************************************************************
'cssファイル出力
sw = New System.IO.StreamWriter(fnameW2, False, System.Text.Encoding.GetEncoding("shift-jis"))
sw.WriteLine("body{background-color:#2F4F4F;color:#ffffff;}")
sw.WriteLine("p.cline{text-align:center;}")
sw.WriteLine("table.tbl{background-color:#ffffff;text-align:center;font-size:0.8em;font-weight:bold;line-height:120%;}")
For k = 0 To 139
'色名をrgb値に変換
rr = Color.FromName(colname(k)).R
gg = Color.FromName(colname(k)).G
bb = Color.FromName(colname(k)).B
colrgb = "rgb(" & rr.ToString & "," & gg.ToString & "," & bb.ToString & ")"
col_16 = "#" & rr.ToString("X2") & gg.ToString("X2") & bb.ToString("X2")
'バックカラーに応じた文字色の選定
num = CInt(rr) + CInt(gg) + CInt(bb)
If num < 400 Then
ic = 1
If 200 < CInt(gg) And CInt(bb) < 128 Then ic = 0
Else
ic = 0
If CInt(gg) < 150 And 200 < CInt(bb) Then ic = 1
If 200 < CInt(rr) And (CInt(gg) < 150 And 200 < CInt(bb)) Then ic = 0
End If
Select Case ic
Case 0 : strcol = "#000000"
Case 1 : strcol = "#ffffff"
End Select
'バックカラーのrgb指定と文字色の指定書き込み
Select Case scase
Case "rgb" : sw.WriteLine("td.vbcol" & k.ToString("000") & "{background-color:" & colrgb & ";color:" & strcol & ";}")
Case "_16" : sw.WriteLine("td.vbcol" & k.ToString("000") & "{background-color:" & col_16 & ";color:" & strcol & ";}")
End Select
Next k
sw.Close()
Me.Width = 800
Me.Height = 600
WebBrowser1.Url = New Uri(ToolStripLabel1.Text)
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
System.Diagnostics.Process.Start(ToolStripLabel1.Text)
End Sub
End Class