答案之书程序改良版本

答案之书程序改良版本

在这里插入图片描述

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();
        }
        public int maxLength = 4;

        private void Form_AnswerBook_Load(object sender, EventArgs e)
        {
   
            text_numberorbirthday.MaxLength = maxLength;
        }

        private void text_numberorbirthday_TextChanged(object sender, EventArgs e)
        {
   
            if (text_numberorbirthday.Text.Length == 0)
            {
   
                button1.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
   
            if (text_numberorbirthday.Text.Length == 0)
            {
   
                MessageBox.Show("请输入查询内容", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if(text_numberorbirthday.Text.Length != maxLength) {
   
                MessageBox.Show("请输入正确内容", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            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 = "";
            }
            button1.Enabled = false;
        }

        private void btn_clear_Click(object sender, EventArgs e)
        {
   
            text_numberorbirthday.Text = "";
        }
    }
}

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-24 23:48:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-24 23:48:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-24 23:48:02       82 阅读
  4. Python语言-面向对象

    2024-01-24 23:48:02       91 阅读

热门阅读

  1. ABAP ME28 ME2M 增加展示字段增强

    2024-01-24 23:48:02       48 阅读
  2. python基础教程九 抽象三(函数参数续)

    2024-01-24 23:48:02       57 阅读
  3. C++ inline 关键字有什么做用?

    2024-01-24 23:48:02       58 阅读
  4. 【远程工作系列一】如何找远程工作

    2024-01-24 23:48:02       61 阅读
  5. 概念杂记--到底啥是啥?(数据库篇)

    2024-01-24 23:48:02       61 阅读
  6. 汇编中的标签与C语言的函数对比与区别

    2024-01-24 23:48:02       63 阅读
  7. 哪些编程语言和领域最适合应用AIGC技术?

    2024-01-24 23:48:02       47 阅读
  8. git常用命令汇总

    2024-01-24 23:48:02       45 阅读
  9. 基于区块链的算力并网交易平台研究报告(2023)

    2024-01-24 23:48:02       51 阅读