Displaying Form For Output Only And Starting Without Button Click

Welcome Forums General PowerShell Q&A Displaying Form For Output Only And Starting Without Button Click

This topic contains 3 replies, has 3 voices, and was last updated by

 
Moderator
7 months, 1 week ago.

  • Author
    Posts
  • #112205

    Participant
    Topics: 30
    Replies: 41
    Points: 32
    Rank: Member

    I am trying to launch a PowerShell form after a process is finished by grabbing it's exit code. I want this form to basically just display some information in a text box, prompt user, etc. WITHOUT having the user click on a button. Is this possible? After researching for hours, I have not been able to find an answer. I have used a similar form, but all script processes need to be included after "add_click" and then end the script with $form.ShowDialog() . Any ideas how I can get the script to start automatically after the form is loaded?

  • #112207

    Participant
    Topics: 30
    Replies: 41
    Points: 32
    Rank: Member

    After hours of testing and researching, I am finally able to get it to work with "Add_Shown." I just had to turn the script portion into a function and call that function via Add_Shown before loading the form. In this case, the function is called "Start-Script":

    $form.Add_Shown( { Start-Script } )
    
    $drc = $form.ShowDialog()
  • #112208

    Participant
    Topics: 2
    Replies: 876
    Points: 1,354
    Helping Hand
    Rank: Community Hero

    How did you start the other process, via another script or from a form action?

    If you are grabbing the exit code, then you have code running to look for it.

    Just add code to open a message box, no real need to create a form just to display a message.

    Since you are saying you want to do this when the form is loaded, then use the FormLoad, onload or Add_Loaded form event. There are lots of examples on how to do this all over the web. For Example:

    https://stackoverflow.com/questions/36166306/how-do-i-make-a-powershell-wpf-form-run-a-function-when-loaded-and-display-itse

     

  • #112210

    Moderator
    Topics: 8
    Replies: 736
    Points: 2,059
    Helping Hand
    Rank: Community Hero

    Great, and good to know that you found the solution yourself and thanks for sharing it here.

The topic ‘Displaying Form For Output Only And Starting Without Button Click’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort