所以我试图制作一个基本的秒表程序,但我一直收到这个错误"一个新的表达式需要(),[]或{}类型" 这是我的代码:
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
int ms, s, m, h;
Timer timer1 = new Timer
public Form1()
{
InitializeComponent();
ms = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
ms = ms + 1;
if (ms == 9)
{
ms = 0;
s = s + 1;
lblsecond.Text = s.ToString();
if (s == 59)
{
s = 0;
m = m + 1;
lblmin.Text = m.ToString();
if (m == 59)
{
m = 0;
h = h + 1;
lblhur.Text = h.ToString();
{
lblmsec.Text = ms.ToString();
}
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void button3_Click(object sender, EventArgs e)
{
ms = 0;
h = 0;
s = 0;
m = 0;
timer1.Enabled = false;
lblhur.Text = "00";
lblmin.Text = "00";
lblmsec.Text = "00";
lblsecond.Text = "00";
}
}
}
答案 0 :(得分:1)
Timer timer1 = new Timer();
在创建新类时,需要调用类的构造函数。阅读一些有关C#的基础知识教程。你错过了基础知识!
答案 1 :(得分:0)
这一行
Timer timer1 = new Timer();
答案 2 :(得分:0)
您能指定哪条线路给您错误吗?但也可能是这个,你为什么要围绕这个?{/ p>
lblhur.Text = h.ToString();
{
lblmsec.Text = ms.ToString();
}
或者
Timer timer1 = new Timer
到
Timer timer1 = new Timer();
答案 3 :(得分:0)
在这一行
Timer timer1 = new Timer
计时器结束需要()和; ,像这样:
Timer timer1 = new Timer();