Powershell GUI – Function outsourcing

Welcome Forums General PowerShell Q&A Powershell GUI – Function outsourcing

Viewing 2 reply threads
  • Author
    Posts
    • #255830
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Dear forum,
      I have an issue, which I hope, you guys can help me with:
      I am having a window, named “$objForm”

      in which I have implemented a button (called $btn5). By pushing this button, a function (called done) shall be opened, which generates a “close/done-button” to this form (This works fine, as long, as the code is not outsourced as a function)

      in the main window, I have set

      to call the function (when pushing the button), I have

       

      The function looks like this :

      When running the program (the main window), and pushing the button, I get the following:

       

      What I do not understand is: Why can I do a ==> write-Host $WindowName <== in the function
      But a ==> $WindowName.Controls.Add($done) <== does not work in the function?

       

      Thank you very much for any help
      newbi

      • This topic was modified 2 months, 2 weeks ago by newbi200925.
      • This topic was modified 2 months, 2 weeks ago by newbi200925.
      • This topic was modified 2 months, 1 week ago by grokkit.
    • #258767
      Senior Moderator
      Topics: 9
      Replies: 1408
      Points: 5,227
      Helping Hand
      Rank: Community MVP

      $WindowName is a string here as you have defined and won’t have properties and methods of a Form. You should pass a WindowsForm object to the function to consume its members.

    • #258788
      Participant
      Topics: 8
      Replies: 168
      Points: 817
      Helping Hand
      Rank: Major Contributor

      $btn5.add_Click{(done $objForm)}

Viewing 2 reply threads
  • You must be logged in to reply to this topic.