Ping/Tracert Gui - responsive forms

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 3 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Ping/Tracert Gui - responsive forms

Post by lontru »

Hi

I want to create a responsive form so the gui doesnt freeze when used as sample i want to create a gui
where you type in a device/hostname. And then you can ping and tracert without locking the gui at the same time
is this possible at all before i continue this?

Image

So live updating the result in the richtext box doing both at the same time?

https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Ping/Tracert Gui - responsive forms

Post by jvierra »

Just follow the instructions in the article on the link you just posted. Read the article carefully and try al of the example code until you understand the point of the article. Use the custom control sets to implement the code in the article.
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Ping/Tracert Gui - responsive forms

Post by lontru »

I have tried the sample code from the blog and it works but my brain can gasp it.

So i created a simple form and added the custom control "Button - Start Job"

Image

Code: Select all

$buttonStartJob_Click={
	
	$buttonStartJob.Enabled = $false	
	
	#Create a New Job using the Job Tracker
	Add-JobTracker -Name 'JobName' `
	-JobScript {
   		#--------------------------------------------------
		#TODO: Set a script block
		#Important: Do not access form controls from this script block.
    
		Param($Argument1)#Pass any arguments using the ArgumentList parameter
		
		Test-Connection -ComputerName "$($textbox1.Text)" -Count 10
		
		#--------------------------------------------------
	}`
	-CompletedScript {
		Param($Job)
		$results = Receive-Job -Job $Job
		$richtextbox1.Text = $results
		#Enable the Button
		$buttonStartJob.ImageIndex = -1
		$buttonStartJob.Enabled = $true
	}`
	-UpdateScript {
		Param($Job)
		$results = Receive-Job -Job $Job -Keep
		$richtextbox1.Text = $results
		#Animate the Button
		if($null -ne $buttonStartJob.ImageList)
		{
			if($buttonStartJob.ImageIndex -lt $buttonStartJob.ImageList.Images.Count - 1)
			{
				$buttonStartJob.ImageIndex += 1
			}
			else
			{
				$buttonStartJob.ImageIndex = 0		
			}
		}
	}`
	-ArgumentList $null
}
but get this error?

Code: Select all

ERROR: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command
ERROR: again.
ERROR:     + CategoryInfo          : InvalidData: (:) [Test-Connection], ParameterBindingValidationException
ERROR:     + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand
ERROR:     + PSComputerName        : localhost
ERROR:
Attachments
Test-Connection_Gui.psf
(20.8 KiB) Downloaded 146 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Ping/Tracert Gui - responsive forms

Post by jvierra »

Ok. Now that you have mastered that go back and read the article again carefully. You seem to have missed most of the important parts.
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Ping/Tracert Gui - responsive forms

Post by lontru »

Think i understand it a little but seem to work

Code: Select all

$buttonStartJob_Click = {
	$Count = '5'
	$Device = $($textbox1.Text)
	$buttonStartJob.Enabled = $false
	Write-Host "$Device $Count"
	#Create a New Job using the Job Tracker
	Add-JobTracker -Name 'JobName' `
	-JobScript {
   		#--------------------------------------------------
		#TODO: Set a script block
		#Important: Do not access form controls from this script block.
    
		Param($Device,$Count)#Pass any arguments using the ArgumentList parameter
		
		Test-Connection -ComputerName $Device -Count $Count
		
		#--------------------------------------------------
	}`
	-CompletedScript {
		Param($Job)
		$results = Receive-Job -Job $Job
		$richtextbox1.Text = $results
		#Enable the Button
		$buttonStartJob.ImageIndex = -1
		$buttonStartJob.Enabled = $true
	}`
	-UpdateScript {
		Param($Job)
		$results = Receive-Job -Job $Job -Keep
		$richtextbox1.Text = $results
		#Animate the Button
		if($null -ne $buttonStartJob.ImageList)
		{
			if($buttonStartJob.ImageIndex -lt $buttonStartJob.ImageList.Images.Count - 1)
			{
				$buttonStartJob.ImageIndex += 1
			}
			else
			{
				$buttonStartJob.ImageIndex = 0		
			}
		}
	}`
	-ArgumentList $Device,$Count
}
This topic is 5 years and 3 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked