event-handling

Accessing class member variables inside an event handler in Javascript

只谈情不闲聊 提交于 2019-11-28 20:13:42
问题 I have a quick question regarding the proper way to access Javascript class member variables from inside of an event handler that class uses. For example: function Map() { this.x = 0; this.y = 0; $("body").mousemove( function(event) { this.x = event.pageX; // Is not able to access Map's member variable "x" this.y = event.pageY; // Is not able to access Map's member variable "y" }); } Rather than changing the member variable of the "Map" class, the "this.x" in the event handler tries to affect

How to reference right-clicked object in WPF Context Menu item click event handler?

感情迁移 提交于 2019-11-28 19:47:59
In WPF application there is a Grid with a number of objects (they are derived from a custom control). I want to perform some actions on each of them using context menu: <Grid.ContextMenu> <ContextMenu> <MenuItem Name="EditStatusCm" Header="Change status" Click="EditStatusCm_Click"/> </ContextMenu> </Grid.ContextMenu> But in the event handler I cannot get know which of the objects was right-clicked: private void EditStatusCm_Click(object sender, RoutedEventArgs e) { MyCustControl SCurrent = new MyCustControl(); MenuItem menu = sender as MenuItem; SCurrent = menu.DataContext as MyCustControl; //

Asynchronous or Synchronous calling of event handlers in javascript

喜欢而已 提交于 2019-11-28 19:29:34
Are event handlers executed synchronously or asynchronously in JavaScript? Here is JS bin which is showing that event handler is executed synchronously. Code: $('#toclick').bind('custom', function() { for (var i=0; i<100000; i++) {} console.log('Inside click handler'); }); $('#toclick').trigger('custom'); console.log('Outside click handler'); Output: Inside click handler Outside click handler This means if we trigger an event, the code below it won't be executed unless all the event handlers are executed. Am I right ? Bin with multiple event handlers That's correct. All event handlers are

Should WebSocket.onclose be triggered by user navigation or refresh?

和自甴很熟 提交于 2019-11-28 19:10:22
Part 1: Expected behaviour? I'm seeing some inconsistent browser behaviour between Firefox and Chrome in relation to the onclose handler being called. It seems that Chrome does not trigger an onclose if it was caused by a user page navigation/refresh. However, Firefox does trigger the onclose . It seems to me that Firefox may be behaving correctly here: When the WebSocket connection is closed, possibly cleanly, the user agent must create an event that uses the CloseEvent interface, with the event name close, which does not bubble, is not cancelable, has no default action, whose wasClean

Notify when event from another class is triggered [duplicate]

ε祈祈猫儿з 提交于 2019-11-28 19:01:18
This question already has an answer here: How to raise an event on Property Change? 2 answers I have class A { B b; //call this Method when b.Button_click or b.someMethod is launched private void MyMethod() { } ?? } Class B { //here i.e. a button is pressed and in Class A //i want to call also MyMethod() in Class A after the button is pressed private void Button_Click(object o, EventArgs s) { SomeMethod(); } public void SomeMethod() { } ?? } Class A has a instance of Class B. How can this be done? You'll need to declare a public event on class 'B' - and have class 'A' subscribe to it:

Android:how to get any KeyPress event with example?

佐手、 提交于 2019-11-28 18:53:57
i want to get the key value when user pressed any key and also perform action based on the key pressed in android. e.g. if user pressed 'A' key then i want to get that value,compare,do something. Answer to this question should be twofold. It is determined by the way how the key was generated. If it was press on the hardware key, then both approaches described below are valid. If it was press on the software key, then it depends on actual context. 1.) If key was result of the pressing on the soft keyboard that was obtained by long press on the Menu key: You need to carefully override the

Accessing an object's property from an event listener call in Javascript

爱⌒轻易说出口 提交于 2019-11-28 18:44:48
Below I am creating an object in Javascript. Within the constructor I am setting up an event listener. The problem is that when the event gets fired, this.prop cannot be found, and undefined prints out. How do I solve this? var someObj = function someObj(){ this.prop = 33; this.mouseMoving = function() { console.log(this.prop);} document.getElementById("someDiv").addEventListener('mousemove', this.mouseMoving, true); } When the event handler gets called, "this" no longer references the "someObj" object. You need to capture "this" into a local variable that the mouseMoving function will capture

Handle mouse event anywhere with JavaFX

夙愿已清 提交于 2019-11-28 18:42:09
I have a JavaFX application, and I would like to add an event handler for a mouse click anywhere within the scene. The following approach works ok, but not exactly in the way I want to. Here is a sample to illustrate the problem: public void start(Stage primaryStage) { root = new AnchorPane(); scene = new Scene(root,500,200); scene.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("mouse click detected! "+event.getSource()); } }); Button button = new Button("click here"); root.getChildren().add(button); primaryStage.setScene

Pass a return value back through an EventHandler

我的梦境 提交于 2019-11-28 18:37:42
Im trying to write to an API and I need to call an eventhandler when I get data from a table. Something like this: public override bool Run(Company.API api) { SomeInfo _someInfo = new SomeInfo(); if (_someInfo.Results == 1) return true; else return false; using (MyTable table = new MyTable(api)) { table.WhenData += new EventHandler<DataEventArgs<Record>>(table_WhenData); table.WhenDead += new EventHandler<EventArgs>(table_WhenDead); table.Start(); } public void table_WhenData(object sender, DataEventArgs<Record> e) { return true; } The problem that Im having is I dont know how to pass a return

C# event handling (compared to Java)

岁酱吖の 提交于 2019-11-28 17:57:57
问题 I am currently having a hardtime understanding and implementing events in C# using delagates. I am used to the Java way of doing things: Define an interface for a listener type which would contain a number of method definitions Define adapter class for that interface to make things easier if I'm not interested in all the events defined in a listener Define Add, Remove and Get[] methods in the class which raises the events Define protected fire methods to do the dirty work of looping through