YuS_2
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: #Import the WPF assemblies Add-Type -Assembly PresentationFramework Add-Type -Assembly PresentationCore $clock = [Windows.Markup.XamlReader]::Load( (New-Object System.Xml.XmlNodeReader ( [Xml](Get-Content "clock.xaml") ) ) ) ## Create a script block which will update the UI $counter = 0; $updateBlock = { # Update the clock $clock.Resources["Time"] = [DateTime]::Now.ToString("T") } ## Hook up some event handlers $clock.Add_SourceInitialized( { ## Before the window's even displayed ... ## We'll create a timer $timer = new-object System.Windows.Threading.DispatcherTimer ## Which will fire 4 times every second $timer.Interval = [TimeSpan]"0:0:0.25" ## And will invoke the $updateBlock $timer.Add_Tick( $updateBlock ) ## Now start the timer running $timer.Start() if( $timer.IsEnabled ) { Write-Host "Clock is running. Don't forget: RIGHT-CLICK to close it." } else { $clock.Close() Write-Error "Timer didn't start" } } ) $clock.Add_MouseLeftButtonDown( { $_.Handled = $true $clock.DragMove() # WPF Magic! } ) $clock.Add_MouseRightButtonDown( { $_.Handled = $true $timer.Stop() # we'd like to stop that timer now, thanks. $clock.Close() # and close the windows } ) ## Lets go ahead and invoke that update block &$updateBlock ## And then show the window $clock.ShowDialog() |
| Всего записей: 3218 | Зарегистр. 03-02-2009 | Отправлено: 21:32 11-09-2019 | Исправлено: YuS_2, 21:53 11-09-2019 |
|