event-handling

How can I stop processing of further events.

Similar to the KeyPress events, I want whoever is subscribed to the event to be able to set e.Handled in my EventArgs class. If they return true, I no longer want to continue firing events. Any ideas how to implement this? Right now, here is my method: protected void OnDataReceived(SocketAsyncEventArgs e) { if (DataReceived != null)...

SWT: Getting notified of a system device change (USB device connection / disconnection)

I'm writing an SWT application which needs to sit in the system tray and pop up automatically whenever the user connects some USB device (the application serves as its control panel). The way to do this in the native environment (win32 in this case, but I should be platform-independent ultimately) is to listen to the WM_DEVICECHANGE eve...

How to avoid the ding sound when Escape is pressed while a TEdit is focused?

In code I have developed some years ago I have been using this a lot to close the current form on pressing the Escape key at any moment: procedure TSomeForm.FormKeyPress(Sender: TObject; var Key: Char); begin if key = #27 then close; end; This behaviour is defined for the TForm. The form's KeyPreview property is be set to True to ...

Event to close form

In the simulation of a lan messenger in c# I have created a thread that listens to broadcast notifications from remote hosts on lan. In order to listen to the broadcast messages I am calling the sleep function and once again restarting execution of the thread. The problem with this is that when I close my form this thread continues to ru...

In what cases are detaching from events necessary?

I'm not sure if I'm entirely clear on the implications of attaching to events in objects. This is my current understanding, correct or elaborate: 1. Attaching to local class events do not need to be detached Examples: this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); public event EventHandler OnMyCust...

C#: Where should you place event handler delegates?

I have this class: public class GenericEventArgs<T> : EventArgs { public GenericEventArgs() : this(default(T)) {} public GenericEventArgs(T value) { Value = value; } public T Value { get; private set; } } And this event handler delegate for it: public delegate void GenericEventHandler<T>(object sender, GenericEventArgs<T>...

[WPF] Conditional prevention of the textbox change

I have a TextBox, and a TextBlock within the Border. The TextBlock's Text property is bound to TextBox's value. When I type into the TextBox, the Border changes its width according to the TextBlock's new size. There is an event handler for TextBox.TextChanged in which I test whether the size of the border exceeds a certain number. If it...

How to update page data after event handling?

On Page_Init I create a table of dynamically created controls based on a couple of database tables. One of the controls is an ImageButton for moving an list item up the list. What this event handler does is to update the SortOrder column in the database for the affected items. Now the problem is that since the controls are created in th...

WPF focus textbox after Window is restored/activated from minimized state

Hello, I have a simple WPF application where user is able to minimize my application window. After user restores Window from minimized state I need to set focus to certain TextBox. If user before minimizing Window has not changed focus, then after restoring application everything is fine. But problem comes when user has changed focu...

JQuery Autocomplete verify selected value

We are using the autocomplete jquery plugin written by Jörn Zaefferer, and are trying to verify a valid option is entered. The plugin has result() event which fires when a selection is made. This is OK, but I need to check the value in the textbox when a user clicks out too. So we have tried a .change() and .blur() events, but they bo...

Not getting Mouse Out Event

Hi Experts, I've this code in flex where I register a mouse out event listener - ... var b:Button = new Button(); b.addEventListener(MouseEvent.MOUSE_OUT, buttonOutHandler); ... private function buttonOutHandler(evt:MouseEvent):void { ... } Problem that I am facing is that sometimes when I move my mouse out of the display Obj...

AutoEventWireup false on a page with many controls (C#)

Using C#, there is a web form with many controls where the AutoEventWireup is set to false. This forces you to initialize the handlers that you need in the ctor or by overriding OnInit. What about the handling needed for the controls on the page? Adding button Click's, and SelectedIndexChanged's for dropdowns and listboxes, not to many ...

understanding events and event handlers in C#

I understand the purpose of events, especially within the context of creating user interfaces. I think this is the prototype for creating an event. public void EventName(object sender, EventArgs e); but I don't understand event handlers, specifically what they do, why they're needed, and to create one. Could someone please enlighten m...

How to unsubscribe from an event which uses a lambda expression?

I have the following code to let the GUI respond to a change in the collection. myObservableCollection.CollectionChanged += ((sender, e) => UpdateMyUI()); First of all is this a good way to do this? Second: what's the code to unsubscribe from this event? Is it the same but with -= (and then the complete anonymous method again)? ...

Implementing Event-Generator Idiom in Java

I'm trying to implement the Event Generator Idiom (http://www.javaworld.com/javaworld/jw-09-1998/jw-09-techniques.html). I find things to be a bit "odd" when it comes to the observable class though. Let's say I have the following classes: interface BakeryListener + orderReceived(BakeryEvent event) + orderProcessing(BakeryEvent even...

How does an EventHandler know to allow = operator only in defining class?

I started with a question, and in typing the question, found the answer, but instead of deleting, I thought it might be helpful to A) get confirmation, and B) help others. If I have an event, and several places in the application add listeners, what is the best way to remove all listeners at once? For example, I can ... myPage.OnPageOp...

How to make live custom events in jQuery

jQuery has a really handy event binder called live() which will add events to DOM elements on the fly (even for the elements that will be added later to the DOM). The problem is that it's only working on specific events (listed here in documentation). I really want to have live events for focus,blur and change which is not supported by...

Avoid duplicate event subscriptions in C#

How would you suggest the best way of avoiding duplicate event subscriptions? if this line of code executes in two places, the event will get ran twice. I'm trying to avoid 3rd party events from subscribing twice. theOBject.TheEvent += RunMyCode; In my delegate setter, I can effectively run this ... theOBject.TheEvent -= RunMyCode; t...

AS3: How can I fire events when a property is changed in a über class?

I have a TextField inside a Sprite and I always want the alpha of the TextField to be equal to the alpha of the sprite. How can i subscribe to the changes made in the Sprite? I guess i need to fire a PropertychangeEvent some how, but I can't see that sprite supports this out of the box? class TextWidget extends Sprite{ private var t...

Registry Watcher C#

I'm a newbie to WMI and I need to implement RegistryValueChangeEvent in a C# service. I need an event handler that gets triggered each time any one of a set of registry values is changed. I want behavior similar to the FileSystemWatcher class's Changed event, but for registry values. If there's some other technique I could use to acco...