WPF窗口的关闭、最大化、最小化、拖动事件

2016-08-20 10:36:23来源:http://studybao.blog.51cto.com/1772164/1179677作者:StudyBao人点击


0、屏蔽掉WPF窗口自带的最大、最小、关闭等设置Window的属性windowStyle=“none”


00、布局自己的按钮,编写处理函数如下:


1、关闭窗口


privatevoidclose_btn_Click(objectsender,RoutedEventArgse)//关闭{varret=MessageBox.Show("Areyousuretoexitaudit?","Alert",MessageBoxButton.YesNo);if(ret==MessageBoxResult.Yes){ DataProvider.Instance.LoginOut();//终止所有线程Environment.Exit(Environment.ExitCode);}}

2、最小化、最大化窗口


privatevoidMin_btn_Click(objectsender,RoutedEventArgse)//最小化{this.WindowState=System.Windows.WindowState.Minimized;}privatevoidMax_btn_Click(objectsender,RoutedEventArgse)//最大化{this.WindowState=System.Windows.WindowState.Maximized;}
3、鼠标拖动窗口(设置Window 的MouseMove事件)

this.MouseMove+=newMouseEventHandler(Window_MouseMove);privatevoidWindow_MouseMove(objectsender,MouseEventArgse){if(e.LeftButton==MouseButtonState.Pressed){this.DragMove();}}

4、WPF 关闭Page页面


(this.Parent as Window).Close();


5、Page跳转到Window


privatevoidnewWindow_click(objectsender,RoutedEventArgse)Window1win=newWindow1();win.Show();(this.ParentasWindow).Close();

6、Window跳转到Page


privatevoidNewPage_Click(objectsender,RoutedEventArgse){NavigationWindowwindow=newNavigationWindow();window.Source=newUri("Page1.xaml",UriKind.Relative);window.Show();this.Close();}







最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台