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());
    }
}

相关文章:

  • 2022-12-23
  • 2021-08-31
  • 2021-07-15
  • 2022-02-20
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-09
  • 2021-12-21
  • 2021-07-19
  • 2021-06-24
  • 2021-12-14
相关资源
相似解决方案