zoukankan      html  css  js  c++  java
  • C#随机点名程序例子(名字由配置文件提供)

    最近朋友讲课有向我要一个随机点名的小工具,要求是

    1.      用配置文件随时修改学生的姓名

    2.      随机点名,不去重复(就是说有可能会连续点到同一个人,其实这个我有建议去掉的,既然他说不用就不用了,!)

    因为要的急所以我是用易语言写的,想想最近都没怎么写C#的代码,就用C#重新写了一遍,值得注意的是LabelBackColor属性的列表框中只有颜色选择Transparent而达到透明的效果.大家可能认为这没什么,但是我就犯了个错误,窗口有TransparencyK属性,而我一直想在Label中找到这个属性结果当然是走到了一个错误的思路中.不得已去网上找了下才知道这么回事哈!!!我够傻吧!好了不多说了东西很简单,下面是运行截图和代码:

    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;

     

    namespace 随机点名系统

    {

        public partial class Fmain : Form

        {

     

            publicFmain()

            {

                InitializeComponent();

                //==================加载皮肤=====================================================

                //Sunisoft.IrisSkin.SkinEngineskin = new Sunisoft.IrisSkin.SkinEngine();

                //skin.SkinFile= System.Environment.CurrentDirectory + "\\skins\\" +"Emerald.ssk";

                //skin.Active= true;

                //===================================================================================

            }

     

            privatevoid btn_callTheRoll_Click(object sender, EventArgs e)

            {           

                stringpath = System.IO.Directory.GetCurrentDirectory()+"//name.txt";//取程序运行目录下的NAME.TXT文件路径

                Randomrand = new Random(System.Guid.NewGuid().GetHashCode());//实例化一个伪随机数生成器类.          

                string[]str_nameText = File.ReadAllLines(path);//读取路径为path文本文件的文本内容到数组.一行为一个成员所以不用分割了.

                //rand.Next(0,str_nameText.Length)中的第一个参数是最小值,第二个参数是最大值

                lb_name.Text =str_nameText[rand.Next(0, str_nameText.Length)]; //标签文本为取随机数对应到人名.          

                lb_name.ForeColor = Color.Lime;//因为应用的皮肤,所以字体的颜色要重先定义一下.

            }

     

        }

    }

    运行效果图:

    配置文件图:

  • 相关阅读:
    链表--判断一个链表是否为回文结构
    矩阵--“之”字形打印矩阵
    二叉树——平衡二叉树,二叉搜索树,完全二叉树
    链表--反转单向和双向链表
    codeforces 490C. Hacking Cypher 解题报告
    codeforces 490B.Queue 解题报告
    BestCoder19 1001.Alexandra and Prime Numbers(hdu 5108) 解题报告
    codeforces 488A. Giga Tower 解题报告
    codeforces 489C.Given Length and Sum of Digits... 解题报告
    codeforces 489B. BerSU Ball 解题报告
  • 原文地址:https://www.cnblogs.com/fanghui/p/2774276.html
Copyright © 2011-2022 走看看