Created
March 30, 2018 04:04
-
-
Save skysan87/3bcd7c4e9f018a5c67205ed5cc49a019 to your computer and use it in GitHub Desktop.
[powershell]CountDownTimer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -Assembly System.Windows.Forms | |
function Format-Time | |
{ | |
Param([int]$value) | |
<# | |
.description | |
計測時間(秒)を時分秒に変換します | |
#> | |
[int]$Unit_Hour = 60 * 60 | |
[int]$Unit_Minite = 60 | |
$hour = [System.Math]::Truncate($value / $Unit_Hour) | |
$minute = [System.Math]::Truncate(($value % $Unit_Hour) / $Unit_Minite) | |
$seconds = [System.Math]::Truncate(($value % $Unit_Hour) % $Unit_Minite) | |
return [string]::Format("{0,2}時間{1,2}分{2,2}秒", $hour, $minute, $seconds) | |
} | |
function Visual-Timer | |
{ | |
# タスク名の入力 | |
$timerPeriod = Read-Host "何分?" | |
[int]$minutes = 0 | |
# 入力値チェック | |
if([int]::tryParse($timerPeriod, [ref]$minutes) -eq $false) | |
{ | |
return; | |
} | |
$taskName = $timerPeriod + "分タイマー" | |
try | |
{ | |
for($loop = 60 * $minutes; $loop -gt 0; $loop--) | |
{ | |
$message = $taskName + " 残り " + (Format-Time $loop) | |
Write-Progress -Activity $message | |
Start-Sleep -Seconds 1 | |
} | |
#最前面に表示 | |
#===== Formの作成 ===== | |
$form = New-Object System.Windows.Forms.Form | |
$form.TopMost = $True | |
$form.Text = "Timer" | |
$form.Width = 150 | |
$form.Height = 100 | |
$form.StartPosition = "CenterScreen" | |
$form.FormBorderStyle = [Windows.Forms.FormBorderStyle]::FixedToolWindow | |
#===== ラベルの作成 ===== | |
$label = New-Object System.Windows.Forms.Label | |
$label.Location = New-Object System.Drawing.Point(50,10) | |
$label.Size = New-Object System.Drawing.Size(100,20) | |
$label.Text = "時間です" | |
$form.Controls.Add($label) | |
#===== [閉じる]ボタンの作成 ===== | |
$btnClose = New-Object System.Windows.Forms.Button | |
$btnClose.Location = New-Object System.Drawing.Point(40, 30) | |
$btnClose.Text = "OK" | |
$btnClose.Add_Click({$form.DialogResult = "OK"; $form.Close()}) | |
$form.Controls.Add($btnClose) | |
$form.ShowDialog() | |
} | |
catch [Exception] | |
{ | |
Write-Output ("Error: $error") | |
} | |
} | |
Visual-Timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment