20230724_MBJC_upperpc/MainWindow.xaml.cs

107 lines
3.2 KiB
C#
Raw Normal View History

2023-12-16 03:58:14 +00:00
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
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
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"));
}
/// <summary>
/// 顶部蓝色区域按钮按下事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
}
/// <summary>
/// 主窗口关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 最大化按钮
/// </summary>
private void MaxButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
}
/// <summary>
/// 最小化按钮
/// </summary>
private void MinButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
}
}
}