event-handling

How to handle keypress events in a Qt console application?

痞子三分冷 提交于 2019-12-17 19:59:18
问题 For example, that when you press "Esc", the application ends. 回答1: Qt doesn't handle console events, it can just read \n -terminated lines from the console. You need to use native APIs or other libraries (curses). 回答2: Here is a workaround for linux. Using these posts Capture characters from standard input without waiting for enter to be pressed https://stackoverflow.com/a/912796/2699984 I've made it like this: ConsoleReader.h #ifndef CONSOLEREADER_H #define CONSOLEREADER_H #include <QThread>

Why to not use a custom class instead of inheriting the EventArgs class

旧城冷巷雨未停 提交于 2019-12-17 19:37:22
问题 I'm wondering why should I use a class that inherits from the EventArgs class instead of using a custom class that will do the same job for me when passing event data? 回答1: You don't have to inherit from EventArgs , but it allows people using your classes to use and handle generic *Handler(object sender, EventArgs e) declarations. If you don't inherit from EventArgs , then they have to use explicitly typed *Handler(object sender, YairsFakeEventArgs e) The same goes for just using custom

Focus and blur jQuery events not bubbling

狂风中的少年 提交于 2019-12-17 19:34:47
问题 With the following html structure: <div> <form><span><input></span></form> </div> <p> and the following jquery code: $('form').on("focus", function(event) { $("p").append("focus no delegation<br>"); }) Why doesn't the focus event ever reach my event handler? Binding the event with a selector parameter works fine: $('form').on("focus", "input", function(event) { $("p").append("focus delegation<br>"); }) Event the next snippet works so the focus event does in fact bubble... $('form').on("focus"

What's wrong with calling Invoke, regardless of InvokeRequired?

那年仲夏 提交于 2019-12-17 18:00:55
问题 I've seen the common setup for cross threading access to a GUI control, such as discussed here: Shortest way to write a thread-safe access method to a windows forms control All the web hits I found describe a similar thing. However, why do we need to check InvokeRequired? Can't we just call Invoke directly? I assume the answer is no, so my real question is 'why'? 回答1: From non-UI threads we can't touch the UI - very bad things can happen, since controls have thread affinity. So from a non-UI

Pass a return value back through an EventHandler

谁都会走 提交于 2019-12-17 17:54:30
问题 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,

How do I create a custom event class in Javascript?

混江龙づ霸主 提交于 2019-12-17 17:44:46
问题 How do I create a custom event class similar to ActionScript? What I mean by that is a class that I can use to fire off my own events, send the necessary data. I don't wanna use third-party libraries like YUI or jQuery to do it. My goal is to be able to send a event that looks like this. document.addEventListener("customEvent", eventHandler, false); function eventHandler(e){ alert(e.para1); } document.dispatchEvent(new CustomEvent("customEvent", para1, para2)); Please no third-party library

Add event handler dynamically having the delegate name in a string

谁说胖子不能爱 提交于 2019-12-17 16:53:25
问题 I need to assign an eventHandler to an object, in this way: _Element.AddHandler(UIElement.MouseLeftButtonUpEvent, new RoutedEventHandler(Vars.Digit), true); but, in fact, I only have a string that contains "Digit" or other method name in the Vars object instance. It is possible to achieve this using reflection or other kind of trick? Thanks. 回答1: Yes, you can find the method with Type.GetMethod, and the event with Type.GetEvent, then add a handler with EventInfo.AddEventHandler. It may be

Getting control name for an event

落爺英雄遲暮 提交于 2019-12-17 16:39:08
问题 In my C# Windows Forms form I have some buttons which are dynamically generated. I assigned the following method on the click event. Is it possible to get the name of the button from which the event is triggered? private void btnBrowsDoc_Click(object sender, EventArgs e) { try { if (openFileDialog1.ShowDialog().Equals(DialogResult.OK)) { gbxDocument.Controls["txtDocument" + count].Text = openFileDialog1.FileName; } else { return; } } catch (Exception ex) { //handle the exception } } 回答1: You

How to prevent other event handlers, from first handler, in jQuery

浪尽此生 提交于 2019-12-17 16:31:44
问题 If you attach two or more event handlers to an HTML element, they would be executed one after the other. However, if you want to stop the subsequent event handlers, based on a condition checked in the first handler, then what you should do? For example: <div id='target'> </div> <p id='result'> </p> I'd like to cancel the second handler, if the first handler is cancelled. $(function() { var target = $('#target'), result = $('#result'); target.click(function(e) { result.append('first handler<br

EventHandler with custom arguments

旧街凉风 提交于 2019-12-17 16:21:56
问题 I've been looking for an answer for about an hour on Google but I did not found exactly what I'm looking for. Basically, I have a static Helper class that helps perform many things I do frequently in my App. In this case, I have a method named "CreateDataContextMenu" that creates a context menu on a given TreeView control. public static void CreateDataContextMenu(Form parent, TreeView owner, string dataType) { ... } TreeView owner is the control in which I will associate my context menu. Then