# Tracking windows form events

**URL:** <https://forums.powershell.org/t/tracking-windows-form-events/13105>\
**Category:** PowerShell Help\
**Created:** [September 6, 2019, 4:08pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105 "2019-09-06T16:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamil](https://avatars.discourse-cdn.com/v4/letter/k/94ad74/32.png) [@kamil](https://forums.powershell.org/u/kamil)\
**Post date:** [September 6, 2019, 4:08pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/1 "2019-09-06T16:08:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [September 9, 2019, 6:52pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/2 "2019-09-09T18:52:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kamil](https://avatars.discourse-cdn.com/v4/letter/k/94ad74/32.png) [@kamil](https://forums.powershell.org/u/kamil)\
**Post date:** [September 10, 2019, 11:37am UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/3 "2019-09-10T11:37:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [September 10, 2019, 12:12pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/4 "2019-09-10T12:12:59Z")

</div>

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
```

> **[Register-ObjectEvent (Microsoft.PowerShell.Utility) - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/register-objectevent?view=powershell-7.2&viewFallbackFrom=powershell-6)**
>
> The Register-ObjectEvent cmdlet subscribes to events that are generated by .NET objects on the local computer or on a remote computer. When the subscribed event is raised, it is added to the event queue in your session. To get events in the event...

> **[Manage Event Subscriptions with PowerShell](https://devblogs.microsoft.com/scripting/manage-event-subscriptions-with-powershell/)**
>
> Summary: Bruce Payette shows how to manage event subscriptions with Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, here. I am really excited about the idea I had for this week, and I hope you will be too. I asked Candace Gillhoolley at...

---

<div class="post-metadata">

**Author:** ![kamil](https://avatars.discourse-cdn.com/v4/letter/k/94ad74/32.png) [@kamil](https://forums.powershell.org/u/kamil)\
**Post date:** [September 10, 2019, 2:42pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/5 "2019-09-10T14:42:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [September 18, 2019, 10:20am UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/6 "2019-09-18T10:20:25Z")

</div>

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.

&nbsp;

---

<div class="post-metadata">

**Author:** ![kamil](https://avatars.discourse-cdn.com/v4/letter/k/94ad74/32.png) [@kamil](https://forums.powershell.org/u/kamil)\
**Post date:** [September 19, 2019, 1:36pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/7 "2019-09-19T13:36:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/tracking-windows-form-events/13105/8 "2024-05-16T20:31:21Z")

</div>


