Option Strict On Option Explicit On Public Class Form1 Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click Dim bmp As Bitmap Dim g As Graphics Dim f As Font Dim HSIZE As Integer Dim VSIZE As Integer Dim str As String Dim fnameW As String Dim kxx As Integer Dim kyy As Integer Dim ang As Single Dim kpt As Integer Dim ds As Integer kpt = 2 HSIZE = kpt * 200 VSIZE = kpt * 200 str = "こんにちは!" ds = 5 'pictureBox1の寸法指定 PictureBox1.Width = HSIZE PictureBox1.Height = VSIZE '描画図形を保存可能にする bmp = New Bitmap(HSIZE, VSIZE) PictureBox1.Image = bmp g = Graphics.FromImage(PictureBox1.Image) f = New Font("MS ゴシック", 16) 'Formの寸法をpictureBox1の寸法に合わせる PictureBox1.Left = 0 PictureBox1.Top = ToolStrip1.Height Me.Size = New Size(PictureBox1.Width, PictureBox1.Height + ToolStrip1.Height) '図形・文字表示 g.FillRectangle(Brushes.White, 0, 0, HSIZE, VSIZE) '描画領域を白色で塗りつぶす g.FillEllipse(Brushes.Red, kpt * 50, kpt * 50, kpt * 50, kpt * 50) '円の描画 g.DrawString(str, f, Brushes.Black, kpt * 20, kpt * 20) '文字の描画(水平) '文字列の回転描画 str = "+45度回転" : kxx = kpt * 100 : kyy = kpt * 100 : ang = 45 INC_STR(g, f, str, kxx, kyy, ang) str = "−90度回転" : kxx = kpt * 100 : kyy = kpt * 100 : ang = -90 INC_STR(g, f, str, kxx, kyy, ang) '文字列の回転中心描画 g.FillEllipse(Brushes.Blue, kxx - kpt * ds, kyy - kpt * ds, kpt * ds, kpt * ds) '円の描画 f = New Font("MS ゴシック", 10) str = "文字列回転中心" g.DrawString(str, f, Brushes.Blue, kxx - g.MeasureString(str, f).Width - kpt * ds, kyy - g.MeasureString(str, f).Height) '文字の描画(水平) g.Dispose() f.Dispose() 'ファイルを指定して画像を保存する fnameW = "" saveFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory() If SaveFileDialog1.ShowDialog() = DialogResult.OK Then fnameW = SaveFileDialog1.FileName PictureBox1.Image.Save(fnameW, System.Drawing.Imaging.ImageFormat.Png) End Sub Private Sub INC_STR(ByVal g As Graphics, ByVal f As System.Drawing.Font, ByVal str As String, ByVal kxx As Integer, ByVal kyy As Integer, ByVal ang As Single) '文字列の回転描画 g.ScaleTransform(1, 1) '横・縦の表示比率を設定 g.TranslateTransform(kxx, kyy) '表示位置の設定(表示位置を原点とする座標移動) g.RotateTransform(ang) '表示角度を指定 g.DrawString(str, f, Brushes.Black, 0, 0) '描画実行 g.ResetTransform() '単位行列にリセット End Sub End Class