events

One shot events using Lambda in C#

感情迁移 提交于 2021-02-05 13:40:28
问题 I find myself doing this sort of thing quite often:- EventHandler eh = null; //can't assign lambda directly since it uses eh eh = (s, args) => { //small snippet of code here ((SomeType)s).SomeEvent -= eh; } variableOfSomeType.SomeEvent += eh; Basically I only want to attach an event handler to listen for one shot from the event, I no longer want to stay attached after that. Quite often that "snippert of code" is just one line. My mind is going a bit numb, I'm sure there must be something I

One shot events using Lambda in C#

南楼画角 提交于 2021-02-05 13:38:52
问题 I find myself doing this sort of thing quite often:- EventHandler eh = null; //can't assign lambda directly since it uses eh eh = (s, args) => { //small snippet of code here ((SomeType)s).SomeEvent -= eh; } variableOfSomeType.SomeEvent += eh; Basically I only want to attach an event handler to listen for one shot from the event, I no longer want to stay attached after that. Quite often that "snippert of code" is just one line. My mind is going a bit numb, I'm sure there must be something I

One shot events using Lambda in C#

不问归期 提交于 2021-02-05 13:38:08
问题 I find myself doing this sort of thing quite often:- EventHandler eh = null; //can't assign lambda directly since it uses eh eh = (s, args) => { //small snippet of code here ((SomeType)s).SomeEvent -= eh; } variableOfSomeType.SomeEvent += eh; Basically I only want to attach an event handler to listen for one shot from the event, I no longer want to stay attached after that. Quite often that "snippert of code" is just one line. My mind is going a bit numb, I'm sure there must be something I

C# Passing generic class as an event parameter

喜你入骨 提交于 2021-02-05 11:03:20
问题 I've been working with generics over the last few days and I encountered an issue by trying to pass generic types as parameters in events/delegates. A very friendly member of stack could bring some light into one question about generics I posted last Friday. However, I'd like to bring this up again, because I still don't understand how I am supposed to make it work correctly. In the following code you can see that I have a class "Catalog", which can raise an event, which contains a generic

How to implement a complete event system with Javascript?

别来无恙 提交于 2021-02-05 10:50:34
问题 I'm creating a client-side dynamic blog engine. Now I need a event system to handle many actions from DOM elements and the engine. Such as the engine is loading a article,user is switching a theme... And I don't want to use a library to do this. So far I've done is using a list to store callbacks for a event . But I want each callback works with different objects.Like the DOM event. I may add an id-like property to each object, and store (id,callbacks) in a event.I feel it's not so good.When

Check if window is in background Tkinter

≡放荡痞女 提交于 2021-02-05 09:20:10
问题 So, I'm trying to make an app on tkinter . I've just started learning how this module works. In my app, I have a root window and a child (top leveled) window, and I set the child to be always on top. When I minimize my root window, the child window also minimizes, because I have defined that condition. My problem is when I select other window. When I do it, the child window still stays on top and I want to know if there is a way to know if my root window is in background, a.k.a.: I'm not

Why onchange function not called when checkbox changed using checked property

删除回忆录丶 提交于 2021-02-05 08:36:26
问题 Checkbox is handled using another button. If I directly click on checkbox then the onchange triggers. But when I change the check box using button, onchange(i.e. show() method) is not called. var checkbox=document.getElementById("x"); var button=document.getElementById("y"); button.addEventListener("click",function(){ checkbox.checked== true ?checkbox.checked=false :checkbox.checked=true; }) var show=function(){ window.alert("onchange called"); } <input type='checkbox' name='xyz' id='x'

Why onchange function not called when checkbox changed using checked property

你。 提交于 2021-02-05 08:36:00
问题 Checkbox is handled using another button. If I directly click on checkbox then the onchange triggers. But when I change the check box using button, onchange(i.e. show() method) is not called. var checkbox=document.getElementById("x"); var button=document.getElementById("y"); button.addEventListener("click",function(){ checkbox.checked== true ?checkbox.checked=false :checkbox.checked=true; }) var show=function(){ window.alert("onchange called"); } <input type='checkbox' name='xyz' id='x'

How to pass a parameter to another class using events

烂漫一生 提交于 2021-02-05 08:23:25
问题 I have a usercontrol which is having one button Usercontrolclass.cs Button click event private void btn_OK_Click(object sender, EventArgs e) { value= Convert.ToDouble(txt_ActualValue.Text); if(getvalue!=null) getvalue(null, new EventArga()); } private variable private int value; property: public double finalvalue { get { return value; } } MainForm.cs I'm using that Usercontrol into this mainform I need to get the value from this class in constructor: Usercontrolclass.getvalue+

Java Swing: How to get TextArea value including the char just typed?

一个人想着一个人 提交于 2021-02-05 07:59:09
问题 What's the best way to get a value of a TextArea after a key is typed, including this character? If I do it in the even listener, textarea.getText() returns the value without the eventual new char. Basically I see two ways: postponing processing with something like invokeLater(). I would prefer a solution without threads. figuring out where to put the char into the text, based on the carret position. Is there any other, simpler? Thanks. Edit: This is what I have: JTextArea textarea =