建设好的网站怎么分享,成华区建设局门户网站,互联网网站设计,平面设计年终总结C# Windows系统一键关机源代码#xff0c;可移植(复制粘贴)到的自己的项目中
exe可执行文件下载
C# 源码下载
using System;
using System.Windows;
using System.Windows.Threading;namespace 关机
{/// summary/// MainWindow.xaml 的交互逻辑/// /summary可移植(复制粘贴)到的自己的项目中
exe可执行文件下载
C# 源码下载
using System;
using System.Windows;
using System.Windows.Threading;namespace 关机
{/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{/// summary/// 关机定时/// /summaryprivate DispatcherTimer shutdown;public MainWindow(){InitializeComponent();WindowStartupLocation WindowStartupLocation.CenterScreen;shutdown new DispatcherTimer();shutdown.Tick new EventHandler(ShowCurTimer);shutdown.Interval new TimeSpan(0, 0, 0, 1, 0);shutdown.Start();try{ }catch (Exception){//this.Dispatcher.Invoke(new Action(delegate { this.Close(); }));}}#region 执行关机public void ShowCurTimer(object sender, EventArgs e){关机();}private void 关机(){System.Diagnostics.ProcessStartInfo ps new System.Diagnostics.ProcessStartInfo();ps.FileName shutdown.exe;ps.Arguments -s -t 1; System.Diagnostics.Process.Start(ps);}#endregion}
}
布局
Window x:Class关机.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:关机mc:IgnorabledTitleMainWindow Height108 Width377 WindowStyleNone AllowsTransparencyTrue ShowInTaskbarTrue Background{x:Null} GridGrid.BackgroundImageBrush//Grid.Background!--时间--Label Content正在关机。。。 FontSize35 Foreground#FF02F3FF HorizontalAlignmentLeft Margin78,24,0,0 VerticalAlignmentTop Height74 Width249//Grid
/Window