问题描述
问题:创建一个程序,该程序由“时钟输入”按钮,“时钟输出”按钮和“标签”组成,以保存总工作时间。
这段代码似乎应该很简单,但是我知道我缺少一些东西。我无法从inButton单击中获取DateTime clockIn,而不能与outButton单击中的TimeSpan一起使用。我对C#还是很陌生,因此欢迎提出任何批评。谢谢!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TimeClock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void inButton_Click(object sender,EventArgs e)
{
DateTime clockIn = DateTime.Now;
}
public void outButton_Click(object sender,EventArgs e)
{
DateTime clockOut = DateTime.Now;
TimeSpan timeWorked = clockOut - clockIn;
string timeWorkedReport = $"Time worked = {timeWorked.Hours} hours,{timeWorked.Minutes} minutes";
timeLabel.Text = timeWorkedReport;
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)