我的第一个程序

      初学c#,去网上看了不少c#教程,其中有我很熟悉的if语句、循环语句等算法。感觉上c#和JAVA差不多,只是编程在一个新的软件Microsoft Visual Studio中进行。于是,我边学c#语言,边在该软件中操练了一下。以下是我编的第一个程序,按下Hello会显示The same to you!; 按数字键会在文本框里显示数字,组成字符串;按loop会显示0~9的字符串;按ok会判断密码是否正确(密码是0123456789);按clear清空文本框的内容。
 
      忘了,先写一个简单的显示Hello框的语句(这是基础):
private void button1_Click(object sender, EventArgs e)
        {
            FrmMSG info;
            info = new FrmMSG("Hello");
            info.ShowDialog();
        }
 
      以下是上面说的那个程序:
private void buttonHello_Click_1(object sender, EventArgs e)
        {
            this.textBox1.Text = "Hello";
            Str1 = "Hello";
        }
        private void buttonLoop_Click(object sender, EventArgs e)
        {
            int myInt = 0;
            String myInput;
            Str1 = "";
            while (myInt < 10)
            {
                myInput = Convert.ToString(myInt);
                Str1 += myInput;
                this.textBox1.Text = Str1;
                myInt++;
             }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 1;
            this.textBox1.Text = Str1;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 2;
            this.textBox1.Text = Str1;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 3;
            this.textBox1.Text = Str1;
        }
        private void button4_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 4;
            this.textBox1.Text = Str1;
        }
        private void button5_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 5;
            this.textBox1.Text = Str1;
        }
        private void button6_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 6;
            this.textBox1.Text = Str1;
        }
        private void button7_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 7;
            this.textBox1.Text = Str1;
        }
        private void button8_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 8;
            this.textBox1.Text = Str1;
        }
        private void button9_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 9;
            this.textBox1.Text = Str1;
        }
        private void button0_Click(object sender, EventArgs e)
        {
            Str1 = Str1 + 0;
            this.textBox1.Text = Str1;
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (Str1 == "0123456789")
            {
                FrmMSG info = new FrmMSG("Your password is correct!");
                info.ShowDialog();
            }
            else if (Str1 == "")
            {
                FrmMSG info = new FrmMSG("Please enter your password!");
                info.ShowDialog();
            }
            else if (Str1 == "Hello")
            {
                FrmMSG info = new FrmMSG("The same to you!");
                info.ShowDialog();
            }
            else
            {
                FrmMSG info = new FrmMSG("Your password is wrong!");
                info.ShowDialog();
            }
        }
        private void buttonClear_Click(object sender, EventArgs e)
        {
            Str1 = "";
            this.textBox1.Text = Str1;
        }
 补充说明一下:Str1是一个自定义的空字符串;info是FrmMSG类的一个对象,这个类调用ShowDialog()方法时,会弹出一个对话框显示自定义的字符串以及当前的系统时间。
     
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s