|
-
Jul 5th, 2024, 08:33 AM
#1
Thread Starter
Lively Member
How to differentiate between event triggered by user interaction and code ?
I am looking for a way to determine if an event was triggered by user interaction or through code. I have seen suggestions in other forums to use a flag and set it accordingly when triggering the event programmatically. However, I am curious if there are any built-in methods or alternative approaches to achieve this.
Referred links:
https://stackoverflow.com/questions/...103966#3103966
https://www.vbforums.com/showthread....event-is-fired
Last edited by IT_Researcher; Jul 7th, 2024 at 11:12 PM.
-
Jul 5th, 2024, 09:32 AM
#2
Re: How to differentiate between event triggered but user interaction and code ?
What event? If you're talking about user interaction then you're generally talking about controls. It would depend on the event but, generally speaking, no. For instance, the TextChanged event simply indicates that the Text property value has changed. How that happens is irrelevant to the event. The event would be raised in the setter of the Text property and there's no way for the code to know how it got there. Also, if there was a way to distinguish how the event was raised, that information would be in the 'e' parameter of the event handler, so any event handler for which the data type of that parameter is EventArgs obviously has no means to provide that information.
-
Jul 5th, 2024, 09:48 PM
#3
Re: How to differentiate between event triggered but user interaction and code ?
If the code that triggers the event is code that you wrote, then a Boolean would certainly work. The code could set the Boolean, but a user would not, so if the Boolean is set, then your code did it. If the Boolean is not set, then the user did it.
My usual boring signature: Nothing
 
-
Jul 8th, 2024, 02:07 AM
#4
Re: How to differentiate between event triggered but user interaction and code ?
 Originally Posted by Shaggy Hiker
If the code that triggers the event is code that you wrote, then a Boolean would certainly work. The code could set the Boolean, but a user would not, so if the Boolean is set, then your code did it. If the Boolean is not set, then the user did it.
Which would require such a Variable to have at least module-scope, since you can only set such a variable outside the Event itself.
If there are multiple events involved OP wants to control if User-Interaction or from Code, it would require one such variable per Event (or an array, Bitfield, whatever)
What about a custom Event-Handler?
Last edited by Zvoni; Jul 8th, 2024 at 02:17 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|