WPF通过出生日期计算年龄/MainWindow.xaml.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPF通过出生日期计算年龄
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void DteBirthday_PreviewKeyDown(object sender, KeyEventArgs e)
{
Console.WriteLine("Hello");
if (e.Key == Key.Enter)
{
try
{
//dteBirthday为空时跳出
DateTime dateTime = (DateTime)dteBirthday.SelectedDate.Value;
}
catch (Exception)
{
return;
}
DateTime now = DateTime.Now;//当前时间用于对比
if (dteBirthday.SelectedDate > DateTime.Now)
{
MessageBox.Show("出生日期不能大于当前时间");
return;
}
int age = now.Year - dteBirthday.SelectedDate.Value.Year;//计算年龄
if (age > 1)
{
if ((now.Month > dteBirthday.SelectedDate.Value.Month) || (now.Month == dteBirthday.SelectedDate.Value.Month && now.Day >= dteBirthday.SelectedDate.Value.Day))
{
tbAge.Text = age.ToString();
cbAge.SelectedIndex = 0;
}
后面还有 51 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。