Launch event progmatically

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

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 7 years and 5 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.
Locked
User avatar
Alcasczar
Posts: 31
Last visit: Sat Jun 22, 2019 9:30 am

Launch event progmatically

Post by Alcasczar »

Apologies if this is the wrong forum, I thought it might be half GUI/Half PowerShell related.

I have a function that leverages the .NET messagebox.open which returns a result based on what clicked OK,Cancel,Yes,No etc. It works! I have the form that displays this message box when it first launches and this works.

What I'd like to do is conditionally execute an event say $buttonSubmit_Click if the response is the user clicked Yes button on the message box.

Here's what I have and what I tried that fails to work, I've tried other variations. I guess I am not sure how to execute it like this or if even possible without some special function or cmdlet. I looked at Register-ObjectEvent but it complained about EventName.

Short of re-creating the entire button click event with duplicated code, is there a way to call the button click event like this?

Code: Select all

$MainForm_Load={

     $Answer = send-messagebox -message "Do you want to run the report?" -caption "Run report now?" -buttontype 4 -boxtype 32
	
	if ($Answer -eq "Yes")
	{
	$buttonSubmit_click
			
	}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Launch event progmatically

Post by jvierra »

Try this"

$buttonSubmit_click.Invoke()
User avatar
Alcasczar
Posts: 31
Last visit: Sat Jun 22, 2019 9:30 am

Re: Launch event progmatically

Post by Alcasczar »

jvierra wrote:Try this"

$buttonSubmit_click.Invoke()
Thank you! Yes that worked!!!
This topic is 7 years and 5 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.
Locked