做摇号器,求指导,新手上路~~~~
我想用C#做一个班级学生的摇号器,但是不用数据库。就是一个独立的小程序,里面可以记录班级人员。不知道能不能做??求大家指导!! --------------------编程问答-------------------- 用一个定时器,设置Interval为50,Enabled为false放一个Label,一个按钮
新建一个局部变量(写在class里面,方法外面)
private Random rnd = new Random();
Timer_Tick里面写:
label1.Text = rnd.Next(0, 50).ToString(); //假设学号是1~50
然后再在Button里面写
timer1.Enabled = !timer1.Enabled;
运行。 --------------------编程问答--------------------
--------------------编程问答-------------------- 用WPF做了一个
//学生姓名列表
List<string> sutList = new List<string>
{
"张三",
"里斯",
"王五"
};
Random rand = new Random();
int index = rand.Next(3);//生成一个小于3的非负随机数
Console.WriteLine(sutList[index]);//打印出随机抽取的学生姓名
xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="400">
<Grid>
<TextBox x:Name="endTextBox" HorizontalAlignment="Left" Height="36" TextWrapping="Wrap" FontSize="16" VerticalAlignment="Top" Width="171" Margin="111,11,0,0"/>
<TextBlock HorizontalAlignment="Left" Margin="10,16,0,0" FontSize="16" TextWrapping="Wrap" VerticalAlignment="Top" Height="36" Width="96"><Run Text="输入班级人数"/></TextBlock>
<Button Content="摇!" HorizontalAlignment="Left" Margin="156,265,0,0" VerticalAlignment="Top" Width="80" RenderTransformOrigin="0.209,-1.241" Height="44" Click="Button_Click_1"/>
<TextBlock x:Name="resultTextBlock" TextWrapping="Wrap" FontSize="90" Foreground="Blue" Margin="111,83,110,73"/>
</Grid>
</Window>
c#
using System;--------------------编程问答-------------------- Random rand = new Random();
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
int end = int.Parse(endTextBox.Text);
var ram = new Random();
int r = ram.Next(1, end);
resultTextBlock.Text = r.ToString();
}
catch
{
MessageBox.Show("请输入一个数字");
}
}
}
}
用这个,随机函数,随便摇 --------------------编程问答-------------------- 嗯 受益匪浅啊 不过我想摇出来的直接是学生姓名 并且可以随时添加 修改 能办到吗 --------------------编程问答--------------------
用个字符 数组存名字
随机数 为数组的 索引不就Ok了 --------------------编程问答-------------------- 你的QQ多少 我直接发到你邮箱里! 我这里有程序! --------------------编程问答-------------------- 就是那种类似于老虎机的 --------------------编程问答--------------------
839811175
太感谢了....谢谢 --------------------编程问答--------------------
嗯 这个倒是懂 可是我想知道那我存进去的人员信息存放在哪了 总不能每次运行程序的时候输入吧 --------------------编程问答--------------------
用个text 读写 就可以了呗
--------------------编程问答--------------------
写错了 是txt
每行写一个
读一行
存一个
就可以了。
每次用的时候都读
你添加的话
可以直接在txt
也可以用程序往txt添加
补充:.NET技术 , C#