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 5 months 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
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Responsive Forms

Post by Genx13 »

I'm having trouble wrapping my head around the responsive forms with the examples from the articles below. Does anyone have a simple form that copies files or something they could share using this method. I really think I just need to see an example of a working script that I can dissect.

https://www.sapien.com/blog/2011/07/15/primalforms-2011-creating-responsive-loops
https://info.sapien.com/index.php/guis/gui-advanced-tips/creating-responsive-loops
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Responsive Forms

Post by jvierra »

The "Start Job" custom control set is also an example. Just place it on a new form and run it. Look at the code and notice what it is doing.
User avatar
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Re: Responsive Forms

Post by Genx13 »

So I looked again at the "Button-Start Job" code along with a longer look at the Creating Responsive Forms and Responsive Loops.

I think It's starting to sink in a bit I'm still not getting something. I used your "Demo-JobChildForm" as a template, I have a main form with one button that opens the child form below. Using the code from the "Creating Responsive Forms" I can get the ping to run and the progress bar to fill. I edited that to try doing a copy-Item but I can't figure out how to get the progress bar to work with the $count variable.

I'm sure I'm doing something wrong i just can't see where. My best guess is I'm doing something wrong with the $UpdateScript code. Also the files do copy the bar just doesn't reflect that.
  1. param
  2. (
  3.     $JobName = 'MyJob'
  4. )
  5.  
  6. $JobScript =
  7. {
  8.     $Source = 'C:\Users\tuser\Desktop'
  9.     $Destination = 'C:\Users\tuser\Documents\TestCopy'
  10.     [int]$Count = $Source.count
  11.    
  12.     for ($i = 0; $i -lt "$($Count)"; $i++)
  13.     {
  14.         #Do some work
  15.         Copy-Item -Path $Source -Destination $Destination -Recurse
  16.         #Start-Sleep -Milliseconds 100
  17.         #Output Progress
  18.         $i + 1
  19.     }
  20. }
  21.  
  22. $UpdateScript =
  23. {
  24.     Param ($Job)
  25.     $results = Receive-Job -Job $Job | Select-Object -Last 1
  26.    
  27.     if ($results -is [int])
  28.     {
  29.         $PBar_Copy.Value = $results
  30.     }
  31. }
  32.  
  33. $CompletedScript =
  34. {
  35.     Param ($Job, $Count)
  36.     $PBar_Copy.Value = $Count
  37. }
  38.  
  39. $formChildForm_Load={
  40.     #TODO: Place custom script here
  41.     Add-JobTracker -Name $JobName -JobScript $jobscript -UpdateScript $updatescript -CompletedScript $completedscript
  42. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Responsive Forms

Post by jvierra »

Copy-Item has no output and will block the loop until it is done. The progress bar will not work here.
User avatar
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Re: Responsive Forms

Post by Genx13 »

Is there any other way to show the progress during a file copy? Would a Marquee Progress bar work?

Do you have any recommendations for show progress on a file copy, that could show a percentage done or anything?

Would Copy-WithProgress work better?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Responsive Forms

Post by jvierra »

No. There is no progress for any blocking command.
This topic is 5 years and 5 months 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