Need Help With Forms and DialogResult

Welcome Forums General PowerShell Q&A Need Help With Forms and DialogResult

Viewing 1 reply thread
  • Author
    Posts
    • #186871
      Participant
      Topics: 1
      Replies: 0
      Points: 19
      Rank: Member

      Hi y'all, I'm not too familiar with PS outside of using it for program cmdlets so I'm in need of a bit of guidance.

      I frankensteined a script to create a form for a user to select a radio button, enter information into a text box, and when the OK button is hit to use that info to search for a specific file on a share. That portion works as intended, hoorah.

      Problem is, I don't want the dialog to close after the OK button is clicked. I know it has to do with the button being set as the AcceptButton and the whole dialogresult bit, but everything I've tried to do with Add_Click to circumvent that hasn't worked either. The pastebin of the script is below if you'd like to offer some advice.

      Thanks in advance.

      https://pastebin.com/9n8tcv3q

    • #187027
      Participant
      Topics: 8
      Replies: 1274
      Points: 1,033
      Helping Hand
      Rank: Community Hero

      The script is basically executing line by line, so the code is just checking if the result is ok and then it finishes. Take a look at the code from Dan Potter in this post, which is generated from Sapien's Powershell Studio. When the button is clicked, it is executing a function using a event (_Click), so the script would not exit.

      https://powershell.org/forums/topic/how-to-auto-close-form-showdialog/

      You can also take a look at WPF:

      https://4sysops.com/archives/create-a-gui-for-your-powershell-script-with-wpf/

      With WPF you can use Visual Studio Express (free) to generate the form and then just wire it into Powershell.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.