我试图在几秒钟内编写一个年龄计算器,但TextBox txtOutput没有获得任何值。没有编译错误,所以它必须是另一个错误,但我无法检测到它。
public partial class Form1 : Form
{
public DateTime bDate;
public Form1()
{
InitializeComponent();
}
private void btnBerechne_Click(object sender, EventArgs e)
{
DateTime birthDate = dtpInput.Value;
txtOutput.Text = GetAge(bDate);
}
public string GetAge(DateTime bDate)
{
DateTime birthDate = dtpInput.Value;
TimeSpan Calculator = DateTime.Now - birthDate;
int x = (int) Calculator.TotalSeconds;
return x.ToString();
}
}
}
任何帮助都会受到赞赏。感谢
答案 0 :(得分:0)
适用于此:
public partial class Form1 : Form
{
public DateTime bDate;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
lblSeconds.Text = GetAge(Convert.ToDateTime(dtpInput.Text));
}
public string GetAge(DateTime bDate)
{
DateTime birthDate = bDate;
TimeSpan Calculator = DateTime.Now - birthDate;
int x = (int)Calculator.TotalSeconds;
return x.ToString();
}
}