MainWindow.xaml.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Drawing;
  3. using System.Windows;
  4. using System.Windows.Input;
  5. using System.Windows.Threading;
  6. namespace BlankApp1.Views
  7. {
  8. /// <summary>
  9. /// Interaction logic for MainWindow.xaml
  10. /// </summary>
  11. public partial class MainWindow : Window
  12. {
  13. private DispatcherTimer ShowTimer;
  14. public MainWindow()
  15. {
  16. InitializeComponent();
  17. this.MaxHeight = SystemParameters.WorkArea.Height + 10; //不遮挡任务栏
  18. this.WindowState = WindowState.Maximized; //默认最大化
  19. btnMax.Content = "\ue65b";
  20. //添加timer
  21. ShowTimer = new System.Windows.Threading.DispatcherTimer();
  22. ShowTimer.Tick += new EventHandler(ShowTime);
  23. ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
  24. ShowTimer.Start();
  25. }
  26. public void ShowTime(object sender, EventArgs e)
  27. {
  28. //获得年月日
  29. this.txtTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  30. }
  31. private void btnClose_Click(object sender, RoutedEventArgs e)
  32. {
  33. MessageBoxResult boxResult = MessageBox.Show("确认退出系统?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
  34. if (boxResult == MessageBoxResult.OK)
  35. {
  36. this.Close();
  37. System.Environment.Exit(0);
  38. }
  39. }
  40. private void btnMax_Click(object sender, RoutedEventArgs e)
  41. {
  42. if (this.WindowState == WindowState.Maximized)
  43. {
  44. this.WindowState = WindowState.Normal;
  45. //iconMd.Kind = MaterialDesignThemes.Wpf.PackIconKind.WindowMaximize;
  46. btnMax.Content = "\ue60d";
  47. }
  48. else
  49. {
  50. this.MaxHeight = SystemParameters.WorkArea.Height + 10;
  51. this.WindowState = WindowState.Maximized;
  52. //iconMd.Kind = MaterialDesignThemes.Wpf.PackIconKind.WindowRestore;
  53. btnMax.Content = "\ue65b";
  54. }
  55. }
  56. private void btnMin_Click(object sender, RoutedEventArgs e)
  57. {
  58. this.WindowState = WindowState.Minimized;
  59. }
  60. private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  61. {
  62. if (e.LeftButton == MouseButtonState.Pressed)
  63. this.DragMove();
  64. }
  65. }
  66. }