12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System.Windows;
- using System.Windows.Input;
- 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;
- this.Left = rcnormal.Left;
- this.Top = rcnormal.Top;
- this.Width = rcnormal.Width;
- this.Height = rcnormal.Height;
- }
- }
- /// <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);
- }
- }
- 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);
- }
- }
- }
- }
- }
|