MainWindow.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Threading;
  3. using System.Windows;
  4. using System.Windows.Input;
  5. using System.Windows.Threading;
  6. using LampInspectionMachine.Log4xml;
  7. namespace LampInspectionMachine.Views
  8. {
  9. /// <summary>
  10. /// MainWindow.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class MainWindow : Window
  13. {
  14. private WindowState _windowState= WindowState.Normal;
  15. public MainWindow()
  16. {
  17. InitializeComponent();
  18. }
  19. Rect rcnormal;//定义一个全局rect记录还原状态下窗口的位置和大小。
  20. /// <summary>
  21. /// 最大化
  22. /// </summary>
  23. private void btnMaximize_Click(object sender, RoutedEventArgs e)
  24. {
  25. if ( _windowState == WindowState.Normal )
  26. {
  27. _windowState = WindowState.Maximized;
  28. rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);//保存下当前位置与大小
  29. this.Left = 0;//设置位置
  30. this.Top = 0;
  31. Rect rc = SystemParameters.WorkArea;//获取工作区大小
  32. this.Width = rc.Width;
  33. this.Height = rc.Height;
  34. }
  35. else
  36. {
  37. _windowState = WindowState.Normal;
  38. Rect rc = SystemParameters.WorkArea;//获取工作区大小
  39. this.Width = rc.Width/2;
  40. this.Height = rc.Height/2;
  41. this.Left = rc.Left / 2;
  42. this.Top = rc.Top / 2;
  43. }
  44. }
  45. /// <summary>
  46. /// 还原
  47. /// </summary>
  48. private void btnNormal_Click(object sender, RoutedEventArgs e)
  49. {
  50. this.WindowState = WindowState.Minimized;
  51. }
  52. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  53. {
  54. //if (this.ActualHeight > SystemParameters.WorkArea.Height || this.ActualWidth > SystemParameters.WorkArea.Width)
  55. //{
  56. // this.WindowState = System.Windows.WindowState.Normal;
  57. // btnMaximize_Click(null, null);
  58. //}
  59. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  60. {
  61. Thread.Sleep(500);
  62. this.InvalidateVisual();
  63. this.UpdateLayout();
  64. }));
  65. }
  66. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  67. {
  68. if ( e.ClickCount == 2 )
  69. {
  70. if ( this.ActualWidth == SystemParameters.WorkArea.Width )
  71. {
  72. btnNormal_Click(null, null);
  73. }
  74. else
  75. {
  76. btnMaximize_Click(null, null);
  77. }
  78. }
  79. }
  80. private void Button_Click(object sender, RoutedEventArgs e)
  81. {
  82. }
  83. private void Button_Click_1(object sender, RoutedEventArgs e)
  84. {
  85. }
  86. }
  87. }