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.
Locked
User avatar
Genx13
Posts: 12
Joined: Fri May 25, 2018 7:46 am

Responsive Forms

Post by Genx13 » Tue Oct 09, 2018 6:24 am

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

User avatar
jvierra
Posts: 12895
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Responsive Forms

Post by jvierra » Tue Oct 09, 2018 8:46 am

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
Joined: Fri May 25, 2018 7:46 am

Re: Responsive Forms

Post by Genx13 » Thu Oct 11, 2018 12:38 pm

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. (
  4.  
  5.     $JobName = 'MyJob'
  6.  
  7. )
  8.  
  9.  
  10.  
  11. $JobScript =
  12.  
  13. {
  14.  
  15.     $Source = 'C:\Users\tuser\Desktop'
  16.  
  17.     $Destination = 'C:\Users\tuser\Documents\TestCopy'
  18.  
  19.     [int]$Count = $Source.count
  20.  
  21.    
  22.  
  23.     for ($i = 0; $i -lt "$($Count)"; $i++)
  24.  
  25.     {
  26.  
  27.         #Do some work
  28.  
  29.         Copy-Item -Path $Source -Destination $Destination -Recurse
  30.  
  31.         #Start-Sleep -Milliseconds 100
  32.  
  33.         #Output Progress
  34.  
  35.         $i + 1
  36.  
  37.     }
  38.  
  39. }
  40.  
  41.  
  42.  
  43. $UpdateScript =
  44.  
  45. {
  46.  
  47.     Param ($Job)
  48.  
  49.     $results = Receive-Job -Job $Job | Select-Object -Last 1
  50.  
  51.    
  52.  
  53.     if ($results -is [int])
  54.  
  55.     {
  56.  
  57.         $PBar_Copy.Value = $results
  58.  
  59.     }
  60.  
  61. }
  62.  
  63.  
  64.  
  65. $CompletedScript =
  66.  
  67. {
  68.  
  69.     Param ($Job, $Count)
  70.  
  71.     $PBar_Copy.Value = $Count
  72.  
  73. }
  74.  
  75.  
  76.  
  77. $formChildForm_Load={
  78.  
  79.     #TODO: Place custom script here
  80.  
  81.     Add-JobTracker -Name $JobName -JobScript $jobscript -UpdateScript $updatescript -CompletedScript $completedscript
  82.  
  83. }

User avatar
jvierra
Posts: 12895
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Responsive Forms

Post by jvierra » Thu Oct 11, 2018 12:50 pm

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
Joined: Fri May 25, 2018 7:46 am

Re: Responsive Forms

Post by Genx13 » Thu Oct 11, 2018 12:57 pm

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?

User avatar
jvierra
Posts: 12895
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Responsive Forms

Post by jvierra » Thu Oct 11, 2018 1:31 pm

No. There is no progress for any blocking command.

Locked