利用timer计时,并根据if语句判断是否合格
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
//1,计时的程序代码
Timer t = new Timer();
DateTime startTime;
TimeSpan span = new TimeSpan();
public Form1()
{
t.Tick += new EventHandler(t_Tick);
t.Interval = 10;
InitializeComponent();
}
void t_Tick(object sender, EventArgs e)
{
span = DateTime.Now - startTime;
textBox1.Text = String.Format("分:{0}秒:{1}", span.Minutes, span.Seconds);
}
private void Form1_Load(object sender, EventArgs e)
{
t.Start();
startTime = DateTime.Now;//在启动时间控件时给初始时间赋值
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
// 2,设计一段程序,经if语句后,弹出消息框提示:在t= 时不合格或者合格//
public static int Main()
{
//判断是否合格
int p0 = 610;
int p1 = 604;
if ((p0 - p1) >= 5)
{
MessageBox.Show("在t=时不合格");//怎么才能显示出时间(秒)?
}
else
{
MessageBox.Show("在t= 时合格");
}
}
}
}
求解:
前面一段程序是利用timer计时,
后面一段程序是通过判断if语句,弹出消息框显示:在t= 时不合格或者合格
错误:
运行时提示定义了不止一个入口;
后面那段程序是不能放到Main()里面吗?要怎么改?
怎么才能让消息框显示具体时间?
如果p1不是确定的数,而是p0在范围(p0>600)的自减,程序要怎么改??? timer ??if????Main????
[解决办法]
你不能自己新增入口函数Main
[解决办法]
Winforms程序的入口在Program.cs文件中,在那个里面的Main中修改。
[解决办法]
1、显示具体时间:MessageBox.Show("在t=" + DateTime.Now + "时合格");//时间参数自己看自己想显示的是什么就加什么
2、在if外加一层for循环