基本信息
源码名称:根据姓氏和性别 取名字 实例源码(入门级)
源码大小:8.47M
文件格式:.rar
开发语言:C#
更新时间:2019-11-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;

namespace GetName
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txt姓.MaxLength = 2;
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            if (RB现代.Checked && RB男.Checked && RB名一个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
                 StreamReader sr1 = new StreamReader("男性名现代.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r1 = new Random();
                int i1 = r1.Next(0, n1);
                textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
            
                timer1.Enabled = true;
            }
            else if (RB现代.Checked && RB男.Checked && RB名两个字.Checked && txt姓.Text.Trim() != String.Empty)
            {

                StreamReader sr1 = new StreamReader("男性名现代两个字.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
        
                Random r2 = new Random();
                 int  i1 = r2.Next(0, n1);
                 textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
                timer1.Enabled = true;
            }
            else if (RB古代.Checked && RB男.Checked && RB名一个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
              StreamReader sr1 = new StreamReader("男性名现代.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r1 = new Random();
                int i1 = r1.Next(0, n1);
                textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
                timer1.Enabled = true;
            }
        
            else  if (RB古代.Checked && RB男.Checked && RB名两个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
                StreamReader sr1 = new StreamReader("男性名现代两个字.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r1 = new Random();
                int i1 = r1.Next(0,n1);
                textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
                timer1.Enabled = true;
            }
            else if (RB现代.Checked && RB女.Checked && RB名一个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
                StreamReader sr1 = new StreamReader("女性名现代.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r1 = new Random();
                int i1 = r1.Next(0, n1);
                textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
                timer1.Enabled = true;
            }
            else if (RB古代.Checked && RB女.Checked && RB名一个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
                StreamReader sr1 = new StreamReader("女性名现代.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r1 = new Random();
                int i1 = r1.Next(0, n1);
                textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
                timer1.Enabled = true;
            }
            else if (RB现代.Checked && RB女.Checked && RB名两个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
                StreamReader sr1 = new StreamReader("女性名现代两个字.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r2 = new Random();
               int i1 = r2.Next(0, n1);
               textBox1.Text  = txt姓.Text   al1[i1].ToString();
               textBox1.Text  = " ";
               timer1.Enabled = true;
            }
            else if (RB古代.Checked && RB女.Checked && RB名两个字.Checked && txt姓.Text.Trim() != String.Empty)
            {
                StreamReader sr1 = new StreamReader("女性名现代两个字.txt", System.Text.Encoding.GetEncoding("gb2312"));
                ArrayList al1 = new ArrayList();
                string line1;
                int n1 = 0;
                while ((line1 = sr1.ReadLine()) != null)
                {
                    al1.Add(sr1.ReadLine());
                    n1  ;
                }
                Random r2 = new Random();
                int i1 = r2.Next(0, n1);
                textBox1.Text  = txt姓.Text   al1[i1].ToString();
                textBox1.Text  = " ";
                timer1.Enabled = true;
            }
            else
            {
                MessageBox.Show("需要全部选满","警告",MessageBoxButtons.OK,MessageBoxIcon.Stop);
            }
            }

        private void txt姓_KeyPress(object sender, KeyPressEventArgs e)
        {
                Regex rg = new Regex("^[\u4e00-\u9fa5]$");  //正则表达式
                if (!rg.IsMatch(e.KeyChar.ToString())) 
                {
                      e.Handled = true;
                }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            button1_Click(sender, e); 
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
           }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
       
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
       }
        
        }