How to find out, if the toolbar icon or the notifyicon is clicked
-
Hello, I just want to find out if the tollbaricon or the notifyicon ist clicked. I know how to do that in a own class. My problem is, that I have a while-loop and in this one, I must check if one of the button is klicked. (Because only then the while have to break.) May you help me? May you have other ideas how i can realize it?
-
Hello, I just want to find out if the tollbaricon or the notifyicon ist clicked. I know how to do that in a own class. My problem is, that I have a while-loop and in this one, I must check if one of the button is klicked. (Because only then the while have to break.) May you help me? May you have other ideas how i can realize it?
You can't, without playing some very nasty games with DoEvents. The problem is that unless you are explicitly threading your app, the while loop is executing on the same thread as the rest of the UI elements - so the click action won't get honoured until after the loop has finished and the event handler that started it has returned control to the system. It's like a man who is so busy concentrating on what's in front of him while he is driving, that he doesn't notice the fire engine trying to get past! You can do it, but you have to change the way your application works, and move the loop into a separate thread. You can then set up an "terminate" variable which you check in the loop, and set in the Click event handler. Have a look at the BackgroundWorker Class (System.ComponentModel)[^] - it provides a safe and easy way to do this, but be aware that you cannot access any UI elements except on the same thread they were created on - if you try to do that inside your loop using a BackgroundWorker you will get a "Cross thread exception" and that means you need to use Invoke to move the access back onto the original thread. This isn't a simple subject and it's probably an idea if you do some background reading on Threading first before you get too complicated.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
You can't, without playing some very nasty games with DoEvents. The problem is that unless you are explicitly threading your app, the while loop is executing on the same thread as the rest of the UI elements - so the click action won't get honoured until after the loop has finished and the event handler that started it has returned control to the system. It's like a man who is so busy concentrating on what's in front of him while he is driving, that he doesn't notice the fire engine trying to get past! You can do it, but you have to change the way your application works, and move the loop into a separate thread. You can then set up an "terminate" variable which you check in the loop, and set in the Click event handler. Have a look at the BackgroundWorker Class (System.ComponentModel)[^] - it provides a safe and easy way to do this, but be aware that you cannot access any UI elements except on the same thread they were created on - if you try to do that inside your loop using a BackgroundWorker you will get a "Cross thread exception" and that means you need to use Invoke to move the access back onto the original thread. This isn't a simple subject and it's probably an idea if you do some background reading on Threading first before you get too complicated.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
mh okay thankyou
-
mh okay thankyou
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...