Button event handler not working

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
CoryEtmund51
Posts: 8
Last visit: Tue Aug 11, 2020 7:54 am

Button event handler not working

Post by CoryEtmund51 »

Product, version and build: PowerShell Studio 5.4.143.0
32 or 64 bit version of product: 64
Operating system: Windows 10 Enterprise
32 or 64 bit OS: 64

I have to be missing something kind of silly in this. I have a PowerShell form (.psf), and on this form I have three buttons. Only this one button does not work. The name of the button is "$btnRefresh" and it's event handler is below:

$btnRefresh_Click={
[System.Windows.Forms.MessageBox]::Show("Please select a region near the top of the form")
}

It is obviously very simple, it should just display that message in a new small window when that button is clicked correct? I made it like this just to help troubleshoot. I have an exit & remove buttons as well and they both work fine when I run the exact same code in their event handlers.

Why is this happening?
cody m

Re: Button event handler not working

Post by cody m »

Do you have $btnRefresh_Click set for that buttons click action event?
Attachments
ButtonAction.JPG
ButtonAction.JPG (21.73 KiB) Viewed 2666 times
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Button event handler not working

Post by mxtrinidad »

Hum! Did you manually add the $btnRefresh_Click event yourself?

The button won't work if you add the event manually. Simply double-click on the button and it will add the event (emtpy) and then you can add the code. It will work as expected!

In your case, because you added the event manually, it will work. Next time add the button, then double-click and add the code afterward.

:)
User avatar
CoryEtmund51
Posts: 8
Last visit: Tue Aug 11, 2020 7:54 am

Re: Button event handler not working

Post by CoryEtmund51 »

I removed the event handler code manually. Once i did that and went back to the Designer, it gave me a popup saying that it needed to create it. After selecting "Insert" the event handler was recreated and now it works. Unfortunately I cannot recall if I typed it myself the first time or if it was automatically created, but it works now. Thank you for the assistance!
This topic is 6 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.