【橙子】C#Winform--动态点名系统

C#Winform–动态点名系统

作者心得

  • 真随机点名
  • 动态点名界面
  • 文件txt直接导入
  • 设置快慢
  • 人数自定义
    -自动读取文件: F:\点名系统.txt

他真的很棒!

源代码
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;
using System.IO;

namespace DMXT
{
public partial class Form1 : Form
{
int mm = 0;
Button[] b = new Button[100];
int x = 0, y = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

        button1.BackColor = Color.FromArgb(0x7fdd2378);
        if (!File.Exists("F:\\点名系统.txt") )
            File.Create("F:\\点名系统.txt" ).Close(); 

        for (int i = 0; i < 100; i++)
        {
            Button button = new Button();
            button.Size = new Size(80, 40);
            button.BackColor = Color.White;
            if (i % 10 == 0 && i != 0)
            {
                x = 0;
                y += 40;
            }
            else if (i % 10 != 0 && i != 0)
            {
                x += 80;
            }
            button.Location = new Point(x, y);
            b[i] = button;
            Controls.Add(b[i]);
        }
        string[] data = new string[100];
        data = read(out int m);
        mm = m;
        for (int i = 0; i < 100; i++)
        {
            b[i].Text = data[i];
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (button1.Text == "开始点名")
        {
            timer1.Enabled = true;
            button1.Text = "停止点名";
            button1.BackColor = Color.Red;
        }
        else
        {
            timer1.Enabled = false;
            button1.Text = "开始点名";
            button1.BackColor = Color.FromArgb(0x7fdd2378);
        }

    }


    Random o = new Random();
    int oo = 0;
    int mid = 99;
    private void timer1_Tick(object sender, EventArgs e)
    {
        oo = o.Next(0, mm);
        b[oo].BackColor = Color.Red;
        if(oo!=mid)
        b[mid].BackColor = Color.White;
        mid = oo;
    }

    private void btn_dis_Click(object sender, EventArgs e)
    {
        timer1.Interval += 50;
    }

    private void btn_add_Click(object sender, EventArgs e)
    {   if(timer1.Interval>50)
        timer1.Interval -= 50;
    }

    public string[] read(out int j)
    {
        j = 0;
        int i = 0;
        string[] data = new string[100];
        StreamReader sr = new StreamReader("F:\\点名系统.txt", Encoding.Default);
        while (sr.EndOfStream != true)
        {
            data[i] = sr.ReadLine();
            i++;
        }
        foreach (string k in data)
        {
            if (k == null)
                goto end;
            j++;
        }
    end:
         return data ;
       
        
    }
}

}

效果截图
(效果不是重点,我也懒的再去自己编名字导入数据了)
在这里插入图片描述
作者的话
这是我第一次使用io流来操作文件
说实在的,c#的io流总感觉有些绕,不如python来的直接
这个也许真有点什么用

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值