erstes commit
This commit is contained in:
183
AuerMenuMain01.ps1
Normal file
183
AuerMenuMain01.ps1
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
|
Add-Type -AssemblyName System.Drawing
|
||||||
|
|
||||||
|
$global:bt_width = 150
|
||||||
|
$global:bt_hight = 23
|
||||||
|
$global:row_distance = 15
|
||||||
|
|
||||||
|
$global:bt_StartPosX = 35
|
||||||
|
$global:bt_StartPosY = -20
|
||||||
|
$global:bt_HightDiff = 25
|
||||||
|
|
||||||
|
$global:NrRows = 3
|
||||||
|
$global:arrCurPosX = New-Object 'Int16[]' $NrRows
|
||||||
|
$global:arrCurPosY = New-Object 'Int16[]' $NrRows
|
||||||
|
$i=0
|
||||||
|
while ($i -lt $NrRows){
|
||||||
|
$arrCurPosX[$i] = $bt_StartPosX + $i*($bt_width+$row_distance)
|
||||||
|
$arrCurPosY[$i] = $bt_StartPosY
|
||||||
|
$i++
|
||||||
|
}
|
||||||
|
|
||||||
|
$global:form = New-Object System.Windows.Forms.Form
|
||||||
|
|
||||||
|
$global:ButtonScriptblock = {
|
||||||
|
$txt = "Hi! I am the general scriptblock!"
|
||||||
|
Write-Host $txt
|
||||||
|
Show-Messagebox $txt
|
||||||
|
}
|
||||||
|
|
||||||
|
$global:ButtonResettedScriptblock = {
|
||||||
|
$txt = "Hi! I am the resetted scriptblock!"
|
||||||
|
Write-Host $txt
|
||||||
|
Show-Messagebox $txt
|
||||||
|
}
|
||||||
|
|
||||||
|
function AddButton([String] $ButtonName, [int] $MyRow) {
|
||||||
|
$MyRow = $MyRow - 1
|
||||||
|
$NewButton = New-Object System.Windows.Forms.Button
|
||||||
|
$arrCurPosY[$MyRow] += $bt_HightDiff
|
||||||
|
$NewButton.Location = New-Object System.Drawing.Size($arrCurPosX[$MyRow], $arrCurPosY[$MyRow])
|
||||||
|
$NewButton.Size = New-Object System.Drawing.Size($bt_width, $bt_hight)
|
||||||
|
$NewButton.Text = $ButtonName
|
||||||
|
$NewButton.Add_Click($ButtonScriptblock)
|
||||||
|
$Form.Controls.Add($NewButton)
|
||||||
|
$NewButton = $null
|
||||||
|
$global:ButtonScriptblock = $ButtonResettedScriptblock
|
||||||
|
}
|
||||||
|
|
||||||
|
function AddHeader([String] $HeaderTXT, [int] $MyRow) {
|
||||||
|
$MyRow = $MyRow - 1
|
||||||
|
$NewText = New-Object System.Windows.Forms.Label
|
||||||
|
$arrCurPosY[$MyRow] += 2 * $bt_HightDiff
|
||||||
|
$NewText.Location = New-Object System.Drawing.Size($arrCurPosX[$MyRow], $arrCurPosY[$MyRow])
|
||||||
|
$NewText.Size = New-Object System.Drawing.Size($bt_width, $bt_hight)
|
||||||
|
$NewText.BackColor = 'white'
|
||||||
|
$NewText.Text = $HeaderTXT
|
||||||
|
$NewText.TextAlign ="MiddleCenter"
|
||||||
|
$NewFontSize = $NewText.Font.Size
|
||||||
|
$FontName = $NewText.Font.Name
|
||||||
|
$FontStyle = "style=bold"
|
||||||
|
$NewText.Font = "$FontName, $NewFontSize, $FontStyle"
|
||||||
|
$Form.Controls.Add($NewText)
|
||||||
|
$NewText = $null
|
||||||
|
}
|
||||||
|
|
||||||
|
function Show-MessageBox {
|
||||||
|
# https://stackoverflow.com/questions/58718191/is-there-a-way-to-display-a-pop-up-message-box-in-powershell-that-is-compatible
|
||||||
|
[CmdletBinding(PositionalBinding=$false)]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory, Position=0)]
|
||||||
|
[string] $Message,
|
||||||
|
[Parameter(Position=1)]
|
||||||
|
[string] $Title,
|
||||||
|
[Parameter(Position=2)]
|
||||||
|
[ValidateSet('OK', 'OKCancel', 'AbortRetryIgnore', 'YesNoCancel', 'YesNo', 'RetryCancel')]
|
||||||
|
[string] $Buttons = 'OK',
|
||||||
|
[ValidateSet('Information', 'Warning', 'Stop')]
|
||||||
|
[string] $Icon = 'Information',
|
||||||
|
[ValidateSet(0, 1, 2)]
|
||||||
|
[int] $DefaultButtonIndex
|
||||||
|
)
|
||||||
|
|
||||||
|
# So that the $IsLinux and $IsMacOS PS Core-only
|
||||||
|
# variables can safely be accessed in WinPS.
|
||||||
|
Set-StrictMode -Off
|
||||||
|
|
||||||
|
$buttonMap = @{
|
||||||
|
'OK' = @{ buttonList = 'OK'; defaultButtonIndex = 0 }
|
||||||
|
'OKCancel' = @{ buttonList = 'OK', 'Cancel'; defaultButtonIndex = 0; cancelButtonIndex = 1 }
|
||||||
|
'AbortRetryIgnore' = @{ buttonList = 'Abort', 'Retry', 'Ignore'; defaultButtonIndex = 2; ; cancelButtonIndex = 0 };
|
||||||
|
'YesNoCancel' = @{ buttonList = 'Yes', 'No', 'Cancel'; defaultButtonIndex = 2; cancelButtonIndex = 2 };
|
||||||
|
'YesNo' = @{ buttonList = 'Yes', 'No'; defaultButtonIndex = 0; cancelButtonIndex = 1 }
|
||||||
|
'RetryCancel' = @{ buttonList = 'Retry', 'Cancel'; defaultButtonIndex = 0; cancelButtonIndex = 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
$numButtons = $buttonMap[$Buttons].buttonList.Count
|
||||||
|
$defaultIndex = [math]::Min($numButtons - 1, ($buttonMap[$Buttons].defaultButtonIndex, $DefaultButtonIndex)[$PSBoundParameters.ContainsKey('DefaultButtonIndex')])
|
||||||
|
$cancelIndex = $buttonMap[$Buttons].cancelButtonIndex
|
||||||
|
|
||||||
|
if ($IsLinux) {
|
||||||
|
Throw "Not supported on Linux."
|
||||||
|
}
|
||||||
|
elseif ($IsMacOS) {
|
||||||
|
|
||||||
|
$iconClause = if ($Icon -ne 'Information') { 'as ' + $Icon -replace 'Stop', 'critical' }
|
||||||
|
$buttonClause = "buttons { $($buttonMap[$Buttons].buttonList -replace '^', '"' -replace '$', '"' -join ',') }"
|
||||||
|
|
||||||
|
$defaultButtonClause = 'default button ' + (1 + $defaultIndex)
|
||||||
|
if ($null -ne $cancelIndex -and $cancelIndex -ne $defaultIndex) {
|
||||||
|
$cancelButtonClause = 'cancel button ' + (1 + $cancelIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
$appleScript = "display alert `"$Title`" message `"$Message`" $iconClause $buttonClause $defaultButtonClause $cancelButtonClause" #"
|
||||||
|
|
||||||
|
Write-Verbose "AppleScript command: $appleScript"
|
||||||
|
|
||||||
|
# Show the dialog.
|
||||||
|
# Note that if a cancel button is assigned, pressing Esc results in an
|
||||||
|
# error message indicating that the user canceled.
|
||||||
|
$result = $appleScript | osascript 2>$null
|
||||||
|
|
||||||
|
# Output the name of the button chosen (string):
|
||||||
|
# The name of the cancel button, if the dialog was canceled with ESC, or the
|
||||||
|
# name of the clicked button, which is reported as "button:<name>"
|
||||||
|
if (-not $result) { $buttonMap[$Buttons].buttonList[$buttonMap[$Buttons].cancelButtonIndex] } else { $result -replace '.+:' }
|
||||||
|
}
|
||||||
|
else { # Windows
|
||||||
|
Add-Type -Assembly System.Windows.Forms
|
||||||
|
# Show the dialog.
|
||||||
|
# Output the chosen button as a stringified [System.Windows.Forms.DialogResult] enum value,
|
||||||
|
# for consistency with the macOS behavior.
|
||||||
|
[System.Windows.Forms.MessageBox]::Show($Message, $Title, $Buttons, $Icon, $defaultIndex * 256).ToString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$Click_Button1 = {
|
||||||
|
$txt = "Hi! I am in scriptblock 1!"
|
||||||
|
Write-Host $txt
|
||||||
|
Show-Messagebox $txt
|
||||||
|
}
|
||||||
|
|
||||||
|
$Click_Button2 = {
|
||||||
|
$txt = "Hi! I am in scriptblock 2!"
|
||||||
|
Write-Host $txt
|
||||||
|
Show-Messagebox $txt
|
||||||
|
}
|
||||||
|
|
||||||
|
$Click_Button3 = {
|
||||||
|
$txt = "Hi! I am in scriptblock 3!"
|
||||||
|
Write-Host $txt
|
||||||
|
Show-Messagebox $txt
|
||||||
|
}
|
||||||
|
|
||||||
|
AddHeader "Spalte 1" 1
|
||||||
|
AddHeader "Spalte 2" 2
|
||||||
|
|
||||||
|
$ButtonScriptblock = $Click_Button1
|
||||||
|
AddButton "Button11" 1
|
||||||
|
|
||||||
|
$ButtonScriptblock = $Click_Button2
|
||||||
|
AddButton "Button12" 1
|
||||||
|
|
||||||
|
$ButtonScriptblock = $Click_Button3
|
||||||
|
AddButton "Button21" 2
|
||||||
|
AddButton "Button22" 2
|
||||||
|
|
||||||
|
$i=0
|
||||||
|
$maxPosX =0
|
||||||
|
$maxPosY =0
|
||||||
|
|
||||||
|
while ($i -lt $NrRows){
|
||||||
|
if ($maxPosX -lt $arrCurPosX[$i]) {$maxPosX=$arrCurPosX[$i]}
|
||||||
|
if ($maxPosY -lt $arrCurPosY[$i]) {$maxPosY=$arrCurPosY[$i]}
|
||||||
|
$i++
|
||||||
|
}
|
||||||
|
|
||||||
|
$form.Width =$maxPosX + $bt_StartPosX
|
||||||
|
$form.Height =$maxPosY + 4 * $bt_hight
|
||||||
|
|
||||||
|
$form.text = "***Auer Signal Admin Menu ***"
|
||||||
|
$form.StartPosition = "CenterScreen" #Wird auf dem Hauptbildschirm zentriert angezeigt
|
||||||
|
|
||||||
|
$form.showdialog()
|
||||||
Reference in New Issue
Block a user