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
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
{ //判断是否合格
int p0 = 610;
int p1 = 604; if ((p0 - p1) >= 5)
{ MessageBox.Show("在t=时不合格");//怎么才能显示出时间(秒)? }
else
{ MessageBox.Show("在t= 时合格");
}
程序是从main开始,但不是你自己写的这个
private void Form1_Load(object sender, EventArgs e)
{
}中可以运行,如下图:
修改后:
private void Form1_Load(object sender, EventArgs e)
{ t.Start();
startTime = DateTime.Now;//在启动时间控件时给初始时间赋值
// 2,设计一段程序,经if语句后,弹出消息框提示:在t= 时不合格或者合格//
int p0 = 610;
int p1 = 604; if ((p0 - p1) >= 5)
{
MessageBox.Show("在t=时不合格");//怎么才能显示出时间(秒)?
}
else
{
MessageBox.Show("在t= 时合格");
} }2,问题:
怎么能让运行时消息框显示具体的时间? 如果p1不是确定的数,而是p0在范围(p0>600)的自减,程序要怎么改???
2、在if外加一层for循环
还有能不能在下面指出的地方加一条if语句,使时间t=5时,才弹出下面的消息框???
(直接用语句if(t=5)不对,不会使用timer的时间变量)private void Form1_Load(object sender, EventArgs e)
{ t.Start();
startTime = DateTime.Now;
int p0 = 610; for (int p1 = 610; p1 > 605; p1--)
{
if ((p0 - p1) >= 10)
{ MessageBox.Show("在t=" + span + "时不合格"); }
else
{
//能不能在这加一条if语句,使时间t=5时,才弹出下面的消息框???// MessageBox.Show("在t=" + span + "时合格"); }
}
}