首页 > Windows开发 > 详细

C# Winform hello world

时间:2020-03-22 13:33:48      阅读:77      评论:0      收藏:0      [点我收藏+]
?using System.Windows.Forms;

namespace ConsoleApp1
{
    public class MyForm : Form
    {
        private TextBox txtEnter;
        private Label lblDisplay;
        private Button btnOk;

        public MyForm()
        {
            this.txtEnter = new TextBox();
            this.lblDisplay = new Label();
            this.btnOk = new Button();
            this.Text = "My HelloWin App!";

            this.txtEnter.Location = new System.Drawing.Point(16, 32);
            this.txtEnter.Size = new System.Drawing.Size(264, 20);

            // lblDisplay
            this.lblDisplay.Location = new System.Drawing.Point(16, 72);
            this.lblDisplay.Size = new System.Drawing.Size(264, 128);

            // btnOk
            this.btnOk.Location = new System.Drawing.Point(88, 224);
            this.btnOk.Text = "OK";
            this.btnOk.Click +=
            new System.EventHandler(this.btnOK_Click);

            // MyForm
            this.Controls.AddRange(new Control[] {
                this.txtEnter, this.lblDisplay, this.btnOk});
        }

        private static void Mai1n()
        {
            Application.Run(new MyForm());
        }

        private void btnOK_Click(object sender, System.EventArgs e)
        {
            lblDisplay.Text = txtEnter.Text + "\n" + lblDisplay.Text;
        }
    }
}

build: csc MyForm.cs

技术分享图片

C# Winform hello world

原文:https://www.cnblogs.com/codworm/p/12545218.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!