event-handling

Listening to Events in Main Form from Another Form in C#

人走茶凉 提交于 2019-11-28 06:15:32
问题 I have an application that has a main form and uses an event handler to process incoming data and reflect the changes in various controls on the main form. This works fine. I also have another form in the application. There can be multiple instances of this second form running at any given time. What I'd like to do is have each instance of this second form listen to the event handler in the main form and update controls on its instance of the second form. How would I do this? Here's some

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

青春壹個敷衍的年華 提交于 2019-11-28 06:13:04
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'? 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 thread we must (at a minumum) call Invoke or BeginInvoke . For UI-threads, however - we don't want to call

Winforms user controls custom events

耗尽温柔 提交于 2019-11-28 05:54:57
Is there a way to give a User Control custom events, and invoke the event on a event within the user control. (I'm not sure if invoke is the correct term) public partial class Sample: UserControl { public Sample() { InitializeComponent(); } private void TextBox_Validated(object sender, EventArgs e) { // invoke UserControl event here } } And the MainForm: public partial class MainForm : Form { private Sample sampleUserControl = new Sample(); public MainForm() { this.InitializeComponent(); sampleUserControl.Click += new EventHandler(this.CustomEvent_Handler); } private void CustomEvent_Handler

Watch for MongoDB Change Streams

前提是你 提交于 2019-11-28 05:30:58
问题 We want our Go application to listen to the data changes on a collection. So, googling in search for a solution, we came across MongoDB's Change Streams. That link also exhibits some implementation snippets for a bunch of languages such as Python, Java, Nodejs etc. Yet, there is no piece of code for Go. We are using Mgo as a driver but could not find explicit statements on change streams . Does anyone have any idea on how to watch on Change Streams using that Mgo or any other Mongo driver for

How do I create a custom event class in Javascript?

怎甘沉沦 提交于 2019-11-28 04:57:06
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 solutions. A method that worked for me was to call document.createEvent(), init it and dispatch it with

Qt - top level widget with keyboard and mouse event transparency?

一个人想着一个人 提交于 2019-11-28 04:52:49
I want an app's main window to ignore mouse and keyboard events, passing them to applications underneath it in the window manager Z-order. I see how to make child widgets ignore keyboard or mouse events, but how about the main window? I'm trying to make a desktop widget that always sits just over the background and is totally invisible to keyboard and mouse events. (Pass through) Qt::X11BypassWindowManagerHint gets me keyboard pass through (although sadly X11 specific, but fine for now), so how about mouse events? Is there a OS-agnostic way to be transparent to keyboard events? EDIT: The key

Forwarding events in C#

痴心易碎 提交于 2019-11-28 04:50:59
I'm using a class that forwards events in C#. I was wondering if there's a way of doing it that requires less code overhead. Here's an example of what I have so far. class A { public event EventType EventA; } class B { A m_A = new A(); public event EventType EventB; public B() { m_A.EventA += OnEventA; } public void OnEventA() { if( EventB ) { EventB(); } } } Class A raises the original event. Class B forwards it as EventB (which is essentially the same event). Class A is hidden from other modules so they can't subscribe to EventA directly. What I'm trying to do is reduce the code overhead in

Vanilla JavaScript version of jQuery .click

喜你入骨 提交于 2019-11-28 04:38:42
So maybe I'm just not looking in the right places but I can't find a good explanation of how to do the equivalent of jQuery's $('a').click(function(){ // code here }); in plain old JavaScript? Basically I want to run a function every time an a tag is clicked but I don't have the ability to load jQuery into the page to do it in the way above so I need to know how to do it using plain JavaScript. Kevin Bowersox Working Example: http://jsfiddle.net/6ZNws/ Html <a href="something">CLick Here</a> <a href="something">CLick Here</a> <a href="something">CLick Here</a> Javascript: var anchors =

Does jQuery preserve touch events properties?

家住魔仙堡 提交于 2019-11-28 04:33:55
While this code produces the expected behavior of "1" when touching the screen: document.getElementById('someNodeId').addEventListener('touchmove', touch, true); function touch(evt) { evt.preventDefault(); alert(evt.changedTouches.length); } the same code using a jQuery selector: $('#someNodeId').bind('touchmove', touch); produces the error: "TypeError: Result of expression 'evt.changedTouches'[undefined] is not an object". (Device = iPod Touch OS 3.1.3 (7E18); jQuery 1.4.2). How is this possible and what am I doing wrong? Try $(document).ready (function () { $("#someNodeId").bind("touchmove",

How to handle SelectedIndexChanged event for a ComboBox? [duplicate]

依然范特西╮ 提交于 2019-11-28 04:21:34
问题 This question already has answers here : What event catches a change of value in a combobox in a DataGridViewCell? (4 answers) Closed 3 years ago . I have DataGridView which contains two ComboBox columns. The second ComboBox will be filled with data depending on the selected value from first ComboBox . How to handle the SelectedIndexChanged event for the first ComboBox . 回答1: A great resource for DataGridView questions can be found here: http://www.windowsclient.net/Samples/Go%20To%20Market