標籤:計時器 比賽打分 分數統計 c#計時器
vs2013 +C#開發的演講比賽簡易打分系統, 可以實現錄入選手名稱 和評委分數,去掉最高分和最低分後求平均值 然後減去扣分,得到匯總分數.
下面附帶"走馬燈"字幕滾動和計時器功能.
功能很簡單,附上源碼,僅供參考,歡迎交流.
FORM1 控制項650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/44/F6/wKiom1PjQp3TzlDGAAGQadZsdNo671.jpg" title="form1.jpg" alt="wKiom1PjQp3TzlDGAAGQadZsdNo671.jpg" />
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//打分及排名
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
Dictionary<int, double> dic = new Dictionary<int, double>();
if (e.ColumnIndex > 0 && e.ColumnIndex < 12)
{
for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
{
if (i == 0)
{ }
else if (i == 12 || i == 11)
{
}
else
{
if (dataGridView1.Rows[e.RowIndex].Cells[i].Value != null)
{
string str = dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString();
double d;
if (double.TryParse(str, out d))
{
dic.Add(i, d);
}
else
{
dic.Add(i, 0);
}
}
else
{
dic.Add(i, 0);
}
}
}
double total = 0;
foreach (int key in dic.Keys)
{
total += dic[key];
}
if (this.dataGridView1.Rows[e.RowIndex].Cells[11].Value != null)
{
double d1;
if (double.TryParse(this.dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(), out d1))
{
this.dataGridView1.Rows[e.RowIndex].Cells[12].Value = ((total - dic.Values.Max() - dic.Values.Min()) / 8) - d1;
}
else
{
this.dataGridView1.Rows[e.RowIndex].Cells[12].Value = ((total - dic.Values.Max() - dic.Values.Min()) / 8) - 0;
}
}
else
{
this.dataGridView1.Rows[e.RowIndex].Cells[12].Value = ((total - dic.Values.Max() - dic.Values.Min()) / 8) - 0;
}
}
}
//下面為計時加字幕滾動功能
private int t = 0;
public string GetAllTime(int time)
{
string mm, ss, fff;
int f = time % 60;//s
int s = time / 60;
int m = s / 60; //分
s = s % 60;//秒
if (f < 10)
{
fff = "0" + f.ToString();
}
else
{
fff = f.ToString();
}
//秒格式00
if (s < 10)
{
ss = "0" + s.ToString();
}
else
{
ss = s.ToString();
}
//分格式00
if (m < 10)
{
mm = "0" + m.ToString();
}
else
{
mm = m.ToString();
}
//返回 hh:mm:ss.ff
return mm + ":" + ss + ":" + fff;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void btnstar_Click(object sender, EventArgs e)
{
if (timer1.Enabled == false)
{
this.btnstar.Text = "暫停計時";
this.timer1.Enabled = true;
}
else {
this.btnstar.Text = "開始計時";
this.timer1.Enabled = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
t = t + 1;
this.textBox1.Text = GetAllTime(t);
}
private void btnclear_Click(object sender, EventArgs e)
{
t = 0;
//如果正在計時,則先停止再清零,否則直接清零
if (this.timer1.Enabled == true)
{
this.btnstar_Click(sender, e);
textBox1.Text = GetAllTime(t);
}
else
{
textBox1.Text = GetAllTime(t);
}
}
private void timer2_Tick(object sender, EventArgs e)
{
string tt = textBox2.Text;
string tt1 = tt.Substring(1);
string tt2 = tt1 + tt[0];
textBox2.Text = tt2;
//dataGridView1.CurrentCell.Value
}
private void button1_Click(object sender, EventArgs e)
{
if(timer2.Enabled==true)
{
button1.Text = "開始滾動字幕";
timer2.Enabled = false;
}
else
{
button1.Text = "暫停滾動字幕";
timer2.Enabled = true;
}
}
}
}
本文出自 “苕國馬龍” 部落格,請務必保留此出處http://gaojinghui.blog.51cto.com/3415762/1537047