首页 > Windows开发 > 详细

窗体四则运算。

时间:2015-10-02 18:39:07      阅读:449      评论:0      收藏:0      [点我收藏+]

我用的是窗体来做的  老师教过 比较简单的方法。

一共用了三个窗体

Form1

技术分享

 

 

代码编辑如下:

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;

namespace Windows窗体的调用
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int Count = 0;
private int t = 60;
public static int right = 0;

private void button1_Click(object sender, EventArgs e)
{
label2.Text = t.ToString();
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
RandomNum();
}
private void RandomNum()
{
Random ran=new Random();
int n1,n2;
n1=ran.Next(1,101);
n2=ran.Next(1,101);
textBox1.Text=n1.ToString();
textBox2.Text=n2.ToString();
textBox3.Text="";
Count++;
}

private void timer1_Tick(object sender, EventArgs e)
{
if (t <= 0)
{
timer1.Enabled = false;
textBox3.Enabled = false;
MessageBox.Show("时间到!");
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
t = t - 1;
label2.Text = t.ToString();
}


private void button2_Click(object sender, EventArgs e)
{
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
}

private void button3_Click(object sender, EventArgs e)
{
new Form3().Show();
}

private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
int sum;
sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
if (e.KeyCode == Keys.Enter)
{
if (textBox3.Text == sum.ToString())
right++;
RandomNum();
}
}

private void Form1_Load(object sender, EventArgs e)
{

}

}
}

 

Form2

技术分享

 

 

代码编辑如下:

 

 

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;

namespace Windows窗体的调用
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Form1.Count.ToString();
textBox2.Text = Form1.right.ToString();
textBox3.Text = ((Form1.right / (double)(Form1.Count)) * 100).ToString() + "%";
}

}
}

 

 

Form3:

技术分享

 

 

代码编辑如下:

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;

namespace Windows窗体的调用
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void Form3_Load(object sender, EventArgs e)
{

}
}
}

 

主代码为:

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;

namespace Windows窗体的调用
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void Form3_Load(object sender, EventArgs e)
{

}
}
}

 

测试图为:

技术分享

 

思路就是用窗体构建出简单模型,然后编写代码,用时1小时。

 

窗体四则运算。

原文:http://www.cnblogs.com/houqiqi/p/4852511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!