Mouse Enter Event

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 5 years and 4 weeks 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
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Mouse Enter Event

Post by dank42 »

Hi,

Within my $form_load statement blocks, my script checks for a running process, if that process is running, two buttons are then disabled, however I want those buttons to be enabled when the mouse enters the button(s).

I have had a play around with the events for Mouse Enter and Mouse Leave which work but only once? When the mouse re-enters the control for the second time it remains disabled?

What is the best way to achieve this?

Thanks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Mouse Enter Event

Post by jvierra »

There is no normal reason for this. Without a code sample there is no way to answer.

Create a simple form with only the code needed to demonstrate the issue and upload it. Someone will take a look at it.
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Mouse Enter Event

Post by dank42 »

  1. $form1_Load={
  2.    
  3.     $Check = Get-Process -Name OUTLOOK
  4.    
  5.     if ($Check)
  6.     {
  7.        
  8.         $button1.Enabled = $false
  9.         $button2.Enabled = $false
  10.        
  11.     }
  12.    
  13.    
  14. }
  15.  
  16.  
  17. $button1_MouseEnter={
  18.    
  19.     $button1.Enabled = $true
  20. }
  21.  
  22. $button1_MouseLeave={
  23.    
  24.     $button1.Enabled = $false
  25. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Mouse Enter Event

Post by jvierra »

If you disable a button it won't receive any events.

See attached example.
Attachments
Test-Buttons.psf
(26.29 KiB) Downloaded 115 times
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Mouse Enter Event

Post by dank42 »

Makes sense now, cheers.
This topic is 5 years and 4 weeks 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