Tracking windows form events

Welcome Forums General PowerShell Q&A Tracking windows form events

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

 
Participant
1 day, 13 hours ago.

  • Author
    Posts
  • #175129

    Participant
    Topics: 5
    Replies: 8
    Points: 57
    Rank: Member

    Good day.

    I am looking for a way of blanket tracking events of a form object in windows forms. Something like Register-ObjectEvent -EventName *

    Is it possible?

  • #175600

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Kamil,

    Please provide more detail and/or example of what you are trying to accomplish. If you have any code written already please share where we can assist in identifying any errors. If you are looking for someone to write the code for you that is not the scope of this forum.

  • #175813

    Participant
    Topics: 5
    Replies: 8
    Points: 57
    Rank: Member

    Good day, Jason.

    I am creating a GUI interface based on windows.forms. Now, on the form, there are three objects: datagridview and two buttons. I'd like to log events firing as a user interacts with the form. But to do it comprehensively i have to Register-ObjectEvent for every conceivable EventName. That is why i was wondering is there a way to register an Action scriptblock which would fire for all events no matter what. I'd like to write something like

    Register-ObjectEvent -InputObject $form -EventName *

    But it isn't allowed.

  • #175837

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Kamil,

    What are you adding into the $Form variable? Again we need to see the code to understand what you are trying to accomplish, you are welcome to change what you need to for any proprietary information. However without the code its going to be limited, have you researched the Register-ObjectEvent yet? Below are some links for research.

    Help Register-Object -Full

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/register-objectevent?view=powershell-6

    Manage Event Subscriptions with PowerShell

  • #175930

    Participant
    Topics: 5
    Replies: 8
    Points: 57
    Rank: Member

    i have read both the help and the Scripting Blog article.

    i am looking for a one liner which gets one subscriber subscribed to all (not just one) event types of a given object.

    i've already typed a one liner which, i imagine, would be good to have, but it does not work that way.

  • #178089

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Kamil,

    Sorry for the delay on my end. Been extremely busy from my end. Can you give an example of what you are trying to accomplish? If you are building a GUI, why are you attempting to make it a one liner? Sorry if I'm asking questions that are obvious, brain has to kick back into gear.

     

    • #178461

      Participant
      Topics: 5
      Replies: 8
      Points: 57
      Rank: Member

      All right.

      Imagine a situation where you build a GUI and you want to log ALL events on a form, simply to know what events and in what order happen. In order to do this you have to know the names of all events of all objects in the form including the form itself. Then you have to hard code every event processing scriptblock.

      What if you could, instead of writing Register-ObjectEvent -InputObject $form -EventName "Certain event", write Register-ObjectEvent -InputObject $form -EventName * (notice the asterisk). So that with one Register-ObjectEvent you subscribe to ALL events of an object and all the child objects.

      Regards
      Kamil

You must be logged in to reply to this topic.