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 vcsGTEST { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void toolStripButton1_Click(object sender, EventArgs e) { main_part(); } private void main_part() { Bitmap bmp; Graphics g; Font f; int HSIZE, VSIZE; string str; string fnameW; int kxx,kyy; float ang; int kpt; int ds; 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; this.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){fnameW=saveFileDialog1.FileName;} pictureBox1.Image.Save(fnameW,System.Drawing.Imaging.ImageFormat.Png); } private void INC_STR(Graphics g,System.Drawing.Font f,string str,int kxx,int kyy,float ang) { //文字列の回転描画 g.ScaleTransform(1,1); //横・縦の表示比率を設定 g.TranslateTransform(kxx,kyy); //表示位置の設定(表示位置を原点とする座標移動) g.RotateTransform(ang); //表示角度を指定 g.DrawString(str,f,Brushes.Black,0,0); //描画実行 g.ResetTransform(); //単位行列にリセット } } }