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.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Threading; namespace _20230724_MBJC_upperpc { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { private DispatcherTimer ShowTimer; public MainWindow() { InitializeComponent(); this.MaxHeight = SystemParameters.PrimaryScreenHeight;//防止最大化时系统任务栏被遮盖 //添加timer ShowTimer = new System.Windows.Threading.DispatcherTimer(); ShowTimer.Tick += new EventHandler(showTimer); ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); ShowTimer.Start(); } public void showTimer(object sender, EventArgs e) { this.Datatime.Text = ""; this.Date.Text = ""; this.week.Text = ""; //获得年月日 //this.Datatime.Text += " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //yyyy年MM月dd日 this.Datatime.Text += " " + DateTime.Now.ToString("HH:mm:ss"); //yyyy年MM月dd日 this.Date.Text += " " + DateTime.Now.ToString("yyyy-MM-dd"); this.week.Text += System.DateTime.Today.ToString("dddd", new System.Globalization.CultureInfo("zh-CN")); } /// /// 顶部蓝色区域按钮按下事件 /// /// /// private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); switch (e.ClickCount) { case 2: { WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; break; } } } /// /// 主窗口关闭 /// /// /// private void Button_Click(object sender, RoutedEventArgs e) { this.Close(); } /// /// 最大化按钮 /// private void MaxButton_Click(object sender, RoutedEventArgs e) { this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; } /// /// 最小化按钮 /// private void MinButton_Click(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; } private void Button_Click_1(object sender, RoutedEventArgs e) { } } }