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 vcsFCdialog { public partial class Form1 : Form { int kpt = 1; //拡大率 int HSIZE = 88; //画像横寸法(px) int VSIZE = 31; //画像縦寸法(px) SolidBrush dbrush; SolidBrush sbrush; Color color_S; Color color_E; System.Drawing.Font f1; //-------------------------------------------------------------------------------- public Form1() { InitializeComponent(); } //-------------------------------------------------------------------------------- private void Form1_Load(object sender, EventArgs e) { 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(); } //-------------------------------------------------------------------------------- private void toolStripButton1_Click(object sender, EventArgs e) { PICWRITE(); } //-------------------------------------------------------------------------------- private void PICWRITE() { //作図用変数宣言 PictureBox thePicBox; Bitmap bmp; Graphics g; System.Drawing.Drawing2D.LinearGradientBrush gb; int kx1,ky1,kx2,ky2; //初期化 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 ){ //上辺→下辺 gb = new System.Drawing.Drawing2D.LinearGradientBrush (new Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, System.Drawing.Drawing2D.LinearGradientMode.Vertical); } if(radioButton2.Checked == true ){ //左辺→右辺 gb = new System.Drawing.Drawing2D.LinearGradientBrush (new Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); } if(radioButton3.Checked == true ){ //左上端→右下端 gb = new System.Drawing.Drawing2D.LinearGradientBrush (new Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal); } if(radioButton4.Checked == true ){ //左下端→右上端 gb = new System.Drawing.Drawing2D.LinearGradientBrush (new Rectangle(kx1, ky1, kx2, ky2), color_S, color_E, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal); } //========================================================= //ガンマ補正を有効にする(グラデーション) if(checkBox1.Checked == true){ gb.GammaCorrection = true; }else{ gb.GammaCorrection = false; } //========================================================= //グラデーションで矩形を塗りつぶす g.FillRectangle(gb, kx1, ky1, kx2, ky2); //========================================================= //フォント描画 PLOT(g); f1.Dispose(); gb.Dispose(); g.Dispose(); } //-------------------------------------------------------------------------------- private void PLOT(Graphics g) { string str1; int kxx,kyy; System.Drawing.SizeF TextSize1; System.Drawing.Font f; str1 = toolStripTextBox1.Text; //描画文字選定 if( str1 != ""){ f = new Font(f1.Name, f1.Size, f1.Style); TextSize1 = g.MeasureString(str1, f); kxx = (int)(HSIZE * kpt / 2 - TextSize1.Width / 2); kyy = (int)(VSIZE * kpt / 2 - TextSize1.Height / 2); g.DrawString(str1, f, sbrush, kxx, kyy); //描画実行 f.Dispose(); } } //-------------------------------------------------------------------------------- private void button1_Click(object sender, EventArgs e) { //影の色選定 if (colorDialog1.ShowDialog() == DialogResult.OK) dbrush = new SolidBrush(colorDialog1.Color); } private void button2_Click(object sender, EventArgs e) { //グラデーション始点色選定 if (colorDialog1.ShowDialog() == DialogResult.OK) color_S = colorDialog1.Color; } private void button3_Click(object sender, EventArgs e) { //グラデーション終点色選定 if (colorDialog1.ShowDialog() == DialogResult.OK) color_E = colorDialog1.Color; } private void button4_Click(object sender, EventArgs e) { //フォント色選定 if (colorDialog1.ShowDialog() == DialogResult.OK) sbrush = new SolidBrush(colorDialog1.Color); } private void button5_Click(object sender, EventArgs e) { //フォント種別選定 if (fontDialog1.ShowDialog() == DialogResult.OK) f1 = fontDialog1.Font; } //-------------------------------------------------------------------------------- private void toolStripButton2_Click(object sender, EventArgs e) { string fnameW = ""; if(saveFileDialog1.ShowDialog() == DialogResult.OK)fnameW = saveFileDialog1.FileName; pictureBox1.Image.Save(fnameW, System.Drawing.Imaging.ImageFormat.Gif); } //-------------------------------------------------------------------------------- } }