min10

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

using System;
using System.Windows.Forms;
using System.Drawing;

public class Class1

{
     public Class1()
     {
     }

    static void Main()
    {
        CreatForm();
    }

    public static void CreatForm()
    {
        Form form1 = new Form();

        TextBox textBox1 = new TextBox();
        textBox1.Text = "Hello world!";
        textBox1.Name = "textBox1";
        textBox1.Width = 200;
        textBox1.Height = 100;
        textBox1.Multiline = true;
        textBox1.ScrollBars = ScrollBars.Vertical;
        textBox1.AcceptsReturn = true;
        textBox1.AcceptsTab = true;
        textBox1.WordWrap = true;
        textBox1.Location = new Point(10,10);

        Button button1 = new Button();
        button1.Text = "Show";
        button1.Location = new Point(10, textBox1.Height + 20);
        button1.Click += new EventHandler(button1_Click);

        Button button2 = new Button();
        button2.Text = "Cancel";
        button2.Location = new Point(button1.Right + 10, textBox1.Height + 20);

        form1.AcceptButton = button1;
        form1.CancelButton = button2;
        form1.Controls.Add(button1);
        form1.Controls.Add(button2);
        form1.Controls.Add(textBox1);
        form1.StartPosition = FormStartPosition.CenterScreen;
        form1.ShowDialog();
    }
    public static void button1_Click(Object sender, EventArgs e)
    {
        Button button = (Button)sender;
        MessageBox.Show(button.Parent.Controls["textBox1"].Text.Trim());
    }
}

posted on 2008-10-09 12:30  min10  阅读(395)  评论(0编辑  收藏  举报