答案之书程序

答案之书程序

需求:用户输入手机号码后4位或者生日,自动生成答案之书对应答案

效果图

答案之书程序_第1张图片

C#代码实现过程

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form_AnswerBook : Form
    {
        public Form_AnswerBook()
        {
            InitializeComponent();
        }

        private void Form_AnswerBook_Load(object sender, EventArgs e)
        {
            text_numberorbirthday.MaxLength = 4;
            if (string.IsNullOrEmpty(text_numberorbirthday.Text)) {
                text_answerbookpages.Text = "0";
            }
        }

        private void text_numberorbirthday_TextChanged(object sender, EventArgs e)
        {
            if (text_numberorbirthday.Text.Length == 4 && int.TryParse(text_numberorbirthday.Text, out int inputValue))
            {
                Random rand = new Random();
                int randomNumber = rand.Next(1, 801);
                text_answerbookpages.Text = randomNumber.ToString();
            }
            else
            {
                text_answerbookpages.Text = "";
            }
        }
    }
}

你可能感兴趣的:(c#)