none
Hilfe bei dynamischen Text in Messagebox benötigt RRS feed

  • Frage

  • 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

    Freitag, 26. Februar 2016 15:40

Antworten

  • Imho gibt es da keine Möglichkeit.
    Du kannst dir aber einfach einen eigenen Dialog mit Winforms oder WPF bauen. Hört sich schwieriger an als es ist.
    Hier ist schonmal ein fertiges Beispiel: LINK
    Es macht aber definitiv Sinn sich mal mit den Grundlagen zu beschäftigen, damit du nicht bei jeder kleinen Änderung auf dem Schlauch stehst. Ich habe zwei Winforms-Grundlagen-Tutorial in meinem Blog (s.u) auf Englisch, gibt aber sicher auch irgendwo was auf Deutsch.

    Achja, bitte schließe noch deinen anderen Thread.
     
    Grüße, Denniver


    Blog: http://bytecookie.wordpress.com

    Kostenloser Powershell Snippet Manager v4: Link ! Neue Version !
    (Schneller, besser + komfortabler scripten.)

    Hilf mit und markiere hilfreiche Beiträge mit dem "Abstimmen"-Button (links) und Beiträge die eine Frage von dir beantwortet haben, als "Antwort" (unten).
    Warum das Ganze? Hier gibts die Antwort.

    • Als Antwort markiert Mitsch1986 Freitag, 26. Februar 2016 19:46
    Freitag, 26. Februar 2016 18:12
    Moderator