123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Threading;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Threading;
- using LampInspectionMachine.Log4xml;
- namespace LampInspectionMachine.Views
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- private WindowState _windowState= WindowState.Normal;
- public MainWindow()
- {
- InitializeComponent();
- }
- Rect rcnormal;//定义一个全局rect记录还原状态下窗口的位置和大小。
- /// <summary>
- /// 最大化
- /// </summary>
- private void btnMaximize_Click(object sender, RoutedEventArgs e)
- {
- if ( _windowState == WindowState.Normal )
- {
- _windowState = WindowState.Maximized;
- rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);//保存下当前位置与大小
- this.Left = 0;//设置位置
- this.Top = 0;
- Rect rc = SystemParameters.WorkArea;//获取工作区大小
- this.Width = rc.Width;
- this.Height = rc.Height;
- }
- else
- {
- _windowState = WindowState.Normal;
- Rect rc = SystemParameters.WorkArea;//获取工作区大小
- this.Width = rc.Width/2;
- this.Height = rc.Height/2;
- this.Left = rc.Left / 2;
- this.Top = rc.Top / 2;
- }
- }
- /// <summary>
- /// 还原
- /// </summary>
- private void btnNormal_Click(object sender, RoutedEventArgs e)
- {
- this.WindowState = WindowState.Minimized;
- }
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- //if (this.ActualHeight > SystemParameters.WorkArea.Height || this.ActualWidth > SystemParameters.WorkArea.Width)
- //{
- // this.WindowState = System.Windows.WindowState.Normal;
- // btnMaximize_Click(null, null);
- //}
- System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- Thread.Sleep(500);
- this.InvalidateVisual();
- this.UpdateLayout();
- }));
-
- }
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if ( e.ClickCount == 2 )
- {
- if ( this.ActualWidth == SystemParameters.WorkArea.Width )
- {
- btnNormal_Click(null, null);
- }
- else
- {
- btnMaximize_Click(null, null);
- }
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
-
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- }
- }
- }
|