欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Powershell使用WPF技术实现弹窗提示实例

程序员文章站 2022-03-20 15:33:33
wpf (windows presentation foundation) 技术能让你创建窗口和对话框。它的优势是在窗体设计时能与代码分开。 这里有个简单的显示弹出消息练...

wpf (windows presentation foundation) 技术能让你创建窗口和对话框。它的优势是在窗体设计时能与代码分开。

这里有个简单的显示弹出消息练习。这个消息是定义在xaml代码中它的实现类似html(但是请区分大小写)。你能轻松的调整字体大小,内容,颜色等等。不需要嵌入任何代码。

复制代码 代码如下:

$xaml = @"
<window
 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>

 <border borderthickness="20" borderbrush="yellow" cornerradius="9" background='red'>
  <stackpanel>
   <label fontsize="50" fontfamily='stencil' background='red' foreground='white' borderthickness='0'>
    system will be rebooted in 15 minutes!
   </label>

   <label horizontalalignment="center" fontsize="15" fontfamily='consolas' background='red' foreground='white' borderthickness='0'>
    worried about losing data? talk to your friendly help desk representative and freely share your concerns!
   </label>
  </stackpanel>
 </border>
</window>
"@

$reader = [system.xml.xmlreader]::create([system.io.stringreader] $xaml)
$window = [system.windows.markup.xamlreader]::load($reader)
$window.allowstransparency = $true
$window.sizetocontent = 'widthandheight'
$window.resizemode = 'noresize'
$window.opacity = .7
$window.topmost = $true
$window.windowstartuplocation = 'centerscreen'
$window.windowstyle = 'none'
# show message for 5 seconds:
$null = $window.show()
start-sleep -seconds 5
$window.close()