/*★ ボタンのクリックで TEXT を取得して表示する 前田 稔 ★*/
using System;
using System.Drawing;
using System.Windows.Forms;
// ツールを貼り付けるとメソッドが追加される
public class MyForm : Form
{
private Button button1;
private TextBox textBox1;
private string str = "C#";
public MyForm()
{
InitializeComponent();
Paint += new PaintEventHandler(MyHandler);
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(83, 205);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 19);
this.textBox1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(94, 231);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// MyForm
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "MyForm";
this.ResumeLayout(false);
this.PerformLayout();
}
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font f = new Font("MS 明朝", 40);
g.DrawString(str, f, Brushes.Blue, new PointF(10F, 80F));
}
private void button1_Click(object sender, EventArgs e)
{
str = textBox1.Text;
Invalidate();
MessageBox.Show(str,"Button Click");
}
}
class form03
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|