Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Hilfe bei dynamischen Text in Messagebox benötigt

$
0
0

Hallo zusammen,

ich habe eine Funktion mit der ich Messageboxen anzeigen lassen kann. 

Nun möchte ich aber den angezeigten Text in einem gewissen Zeitabstand (1 Sekunde) updaten.

Hat einer eine Idee? Hier mal mein Ansatz (Sorry bin noch in der Lernphase...)

function Show-DialogBox {<#
	.SYNOPSIS
		Display a custom dialog box with optional title, buttons, icon and timeout.
		Show-InstallationPrompt is recommended over this function as it provides more customization and uses consistent branding with the other UI components.
	.DESCRIPTION
		Display a custom dialog box with optional title, buttons, icon and timeout. The default button is "OK", the default Icon is "None", and the default Timeout is none.
	.PARAMETER Text
		Text in the message dialog box
	.PARAMETER Title
		Title of the message dialog box
	.PARAMETER Buttons
		Buttons to be included on the dialog box. Options: OK, OKCancel, AbortReTryIgnore, YesNoCancel, YesNo, ReTryCancel, CancelTryAgainContinue. Default: OK.
	.PARAMETER DefaultButton
		The Default button that is selected. Options: First, Second, Third. Default: First.
	.PARAMETER Icon
		Icon to display on the dialog box. Options: None, Stop, Question, Exclamation, Information. Default: None.
	.PARAMETER Timeout
		Timeout period in seconds before automatically closing the dialog box with the return message "Timeout". Default: UI timeout value set in the config XML file.
	.PARAMETER TopMost
		Specifies whether the message box is a system modal message box and appears in a topmost window. Default: $True.
	.EXAMPLE
		Show-DialogBox -Title "Installed Complete" -Text "Installation has completed. Please click OK and restart your computer." -Icon "Information"
	.EXAMPLE
		Show-DialogBox -Title "Installation Notice" -Text "Installation will take approximately 30 minutes. Do you wish to proceed?" -Buttons "OKCancel" -DefaultButton "Second" -Icon "Exclamation" -Timeout 600

		Show-DialogBox -Title "Installed Complete" -Text "Installation has completed. Please click OK and restart your computer." -Icon "Information"
		Show-DialogBox -Title "Installation Notice" -Text "Installation will take approximately 30 minutes. Do you wish to proceed?" -Buttons "OKCancel" -DefaultButton "Second" -Icon "Exclamation" -Timeout 600


	.NOTES
	.LINK
		http://psappdeploytoolkit.codeplex.com
	#>

	#region Parameters
	[CmdletBinding()]
	param(
		[ValidateNotNullorEmpty()]
		[String]$Title,

		[ValidateNotNullorEmpty()]
		[String]$Text,

		[ValidateSet("OK", "OKCancel", "AbortReTryIgnore", "YesNoCancel", "YesNo", "ReTryCancel", "CancelTryAgainContinue")]
		[String]$Button = "OK",

		[ValidateSet("First", "Second", "Third")]
		[String]$DefaultButton = "First",

		[ValidateSet("Exclamation", "Information", "None", "Stop", "Question")]
		[String]$Icon = "Information",

		[ValidateRange(0,100000)]
		[Int]$Timeout = 0,

		[Switch]$TopMost = $True
	)
	#endregion Parameters

	begin {}

	process {
		try {

			#create the COM Object
			$Shell = New-Object -ComObject "WScript.Shell"

			$DialogButtons = @{
				"OK" = 0"OKCancel" = 1"AbortReTryIgnore" = 2"YesNoCancel" = 3"YesNo" = 4"ReTryCancel" = 5"CancelTryAgainContinue" = 6
			}

			$DialogIcons = @{
				"None" = 0"Stop" = 16"Question" = 32"Exclamation" = 48"Information" = 64
			}

			$DialogDefaultButton = @{
				"First" = 0"Second" = 256"Third" = 512
			}

			$DialogTopMost = @{
				"False" = 0"True" = 4096
			}

			$Response = $Shell.Popup($Global:Text, $Timeout, $Title, ($DialogButtons[$Button] + $DialogIcons[$Icon] + $DialogDefaultButton[$DefaultButton] + $DialogTopMost[$TopMost]))

		}
		catch {Write-Host "Fehler"}
	}

	end {}
}

$Timer = New-Object System.Windows.Forms.Timer
$Timer.Interval = 1000
$Timer.Add_Tick({
	$Time = ("Aktuelle Zeit: {0}" -f (Get-Date -Format T))
})

$Timer.Start()

Show-DialogBox -Title "Test" -Text $Time `

Vielen Dank


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>