1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using System.Drawing;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace BlankApp1.Views
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- private DispatcherTimer ShowTimer;
- public MainWindow()
- {
- InitializeComponent();
- this.MaxHeight = SystemParameters.WorkArea.Height + 10; //不遮挡任务栏
- this.WindowState = WindowState.Maximized; //默认最大化
- btnMax.Content = "\ue65b";
- //添加timer
- ShowTimer = new System.Windows.Threading.DispatcherTimer();
- ShowTimer.Tick += new EventHandler(ShowTime);
- ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
- ShowTimer.Start();
- }
- public void ShowTime(object sender, EventArgs e)
- {
- //获得年月日
- this.txtTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- }
- private void btnClose_Click(object sender, RoutedEventArgs e)
- {
- MessageBoxResult boxResult = MessageBox.Show("确认退出系统?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
- if (boxResult == MessageBoxResult.OK)
- {
- this.Close();
- System.Environment.Exit(0);
- }
- }
- private void btnMax_Click(object sender, RoutedEventArgs e)
- {
- if (this.WindowState == WindowState.Maximized)
- {
- this.WindowState = WindowState.Normal;
- //iconMd.Kind = MaterialDesignThemes.Wpf.PackIconKind.WindowMaximize;
- btnMax.Content = "\ue60d";
- }
- else
- {
- this.MaxHeight = SystemParameters.WorkArea.Height + 10;
- this.WindowState = WindowState.Maximized;
- //iconMd.Kind = MaterialDesignThemes.Wpf.PackIconKind.WindowRestore;
- btnMax.Content = "\ue65b";
- }
- }
- private void btnMin_Click(object sender, RoutedEventArgs e)
- {
- this.WindowState = WindowState.Minimized;
- }
- private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed)
- this.DragMove();
- }
- }
- }
|