Option Explicit On Option Strict On Public Class Form1 Private kpt As Integer = 1 '拡大率 Private HSIZE As Integer = 88 '画像横寸法(px) Private VSIZE As Integer = 31 '画像縦寸法(px) Private dbrush As SolidBrush Private sbrush As SolidBrush Private color_S As Color Private color_E As Color Private f1 As System.Drawing.Font Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ToolStripTextBox1.Text = "文字列入力" PictureBox1.Visible = True PictureBox1.Width = kpt * HSIZE PictureBox1.Height = kpt * VSIZE PictureBox1.Left = 10 PictureBox1.Top = ToolStrip1.Height + 10 Label1.Text = "色・Fontの選択" Label2.Text = "グラデーション" Button1.Text = "影の色" Button2.Text = "始端色" Button3.Text = "終端色" Button4.Text = "Font色" Button5.Text = "Font選択" RadioButton1.Checked = True RadioButton2.Checked = False RadioButton3.Checked = False RadioButton4.Checked = False CheckBox1.Checked = True RadioButton1.Text = "Vertical" RadioButton2.Text = "Horizontal" RadioButton3.Text = "ForwardDiagonal" RadioButton4.Text = "BackwardDiagonal" CheckBox1.Text = "Gamma value" '初期化 dbrush = New SolidBrush(Color.Gray) sbrush = New SolidBrush(Color.Black) color_S = Color.White color_E = Color.White f1 = New Font("Arial", kpt * 8, FontStyle.Bold) PICWRITE() End Sub '--------------------------------------------------------------------------------- Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click PICWRITE() End Sub '--------------------------------------------------------------------------------- Private Sub PICWRITE() '作図用変数宣言 Dim thePicBox As PictureBox Dim bmp As Bitmap Dim g As Graphics Dim gb As System.Drawing.Drawing2D.LinearGradientBrush Dim kx1 As Integer Dim ky1 As Integer Dim kx2 As Integer Dim ky2 As Integer '初期化 gb = New System.Drawing.Drawing2D.LinearGradientBrush _ (New Rectangle(0, 0, kpt * HSIZE, kpt * VSIZE), color_S, color_E, _ System.Drawing.Drawing2D.LinearGradientMode.Vertical) '画像描画 thePicBox = PictureBox1 thePicBox.Size = New Size(kpt * HSIZE, kpt * VSIZE) bmp = New Bitmap(thePicBox.Width, thePicBox.Height) thePicBox.Image = bmp g = Graphics.FromImage(thePicBox.Image) g.FillRectangle(dbrush, 0, 0, thePicBox.Width, thePicBox.Height) kx1 = 1 * kpt ky1 = 1 * kpt kx2 = thePicBox.Width - 4 * kpt ky2 = thePicBox.Height - 3 * kpt '========================================================= 'グラデーションのブラシを作成 If RadioButton1.Checked = True Then '上辺→下辺 gb = New System.Drawing.Drawing2D.LinearGradientBrush _ (New Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, _ System.Drawing.Drawing2D.LinearGradientMode.Vertical) End If If RadioButton2.Checked = True Then '左辺→右辺 gb = New System.Drawing.Drawing2D.LinearGradientBrush _ (New Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, _ System.Drawing.Drawing2D.LinearGradientMode.Horizontal) End If If RadioButton3.Checked = True Then '左上端→右下端 gb = New System.Drawing.Drawing2D.LinearGradientBrush _ (New Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, _ System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal) End If If RadioButton4.Checked = True Then '左下端→右上端 gb = New System.Drawing.Drawing2D.LinearGradientBrush _ (New Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, _ System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal) End If '========================================================= 'ガンマ補正を有効にする(グラデーション) If CheckBox1.Checked = True Then gb.GammaCorrection = True Else gb.GammaCorrection = False End If '========================================================= 'グラデーションで矩形を塗りつぶす g.FillRectangle(gb, kx1, ky1, kx2, ky2) '========================================================= 'フォント描画 PLOT(g) f1.Dispose() gb.Dispose() g.Dispose() End Sub '--------------------------------------------------------------------------------- Private Sub PLOT(ByVal g As Graphics) Dim str1 As String Dim kxx As Integer Dim kyy As Integer Dim TextSize1 As System.Drawing.SizeF Dim f As System.Drawing.Font str1 = ToolStripTextBox1.Text '描画文字選定 If str1 <> "" Then f = New Font(f1.Name, f1.Size, f1.Style) TextSize1 = g.MeasureString(str1, f) kxx = CInt(HSIZE * kpt / 2 - TextSize1.Width / 2) kyy = CInt(VSIZE * kpt / 2 - TextSize1.Height / 2) g.DrawString(str1, f, sbrush, kxx, kyy) '描画実行 f.Dispose() End If End Sub '--------------------------------------------------------------------------------- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '影の色選定 If ColorDialog1.ShowDialog = DialogResult.OK Then dbrush = New SolidBrush(ColorDialog1.Color) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'グラデーション始点色選定 If ColorDialog1.ShowDialog = DialogResult.OK Then color_S = ColorDialog1.Color End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'グラデーション終点色選定 If ColorDialog1.ShowDialog = DialogResult.OK Then color_E = ColorDialog1.Color End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'フォント色選定 If ColorDialog1.ShowDialog = DialogResult.OK Then sbrush = New SolidBrush(ColorDialog1.Color) End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'フォント種別選定 If FontDialog1.ShowDialog = DialogResult.OK Then f1 = FontDialog1.Font End Sub '--------------------------------------------------------------------------------- Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click Dim fnameW As String = "" If SaveFileDialog1.ShowDialog() = DialogResult.OK Then fnameW = SaveFileDialog1.FileName PictureBox1.Image.Save(fnameW, System.Drawing.Imaging.ImageFormat.Gif) End Sub '--------------------------------------------------------------------------------- End Class