RUN两个不同形式的textbox.textchange事件一次性...? [英] RUN Two of 2 diffrent form textbox.textchange event at one go...?

查看:62
本文介绍了RUN两个不同形式的textbox.textchange事件一次性...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii,

i有2个表单(form1和form2),每个表单都有一个文本框...



我的问题是如何运行两个Form At on Go的textbox_textchange事件......这样我的搜索时间就会减少...



Prome wat m面对的是textbox1事件正在运行textbox2事件在第一个事件完成后运行...并且我想在两个部分运行两个表单事件...



需要帮助..

提前谢谢

hii ,
i have 2 form ( form1 & form2) and both have one one textbox each ...

My Question is How To Run Both the textbox_textchange event of both the Form At on Go ... so that my searching time should reduce ...

Prome wat m facing is when textbox1 event is running textbox2 event runs after the first one finished ... and wat i wNt is to run both form event at onces ...

need help ..
Thanks in advance

推荐答案

首先,请让我澄清一件事:点击按钮或其他一些UI交互会导致事件和该事件导致您的事件处理程序方法被执行。所以你不要运行事件。



如果你没有实现某种多线程,那么UI线程是唯一运行的线程你的申请流程 - 它一次只能做一件事。正如您可能已经注意到的那样,它还无法更新您的UI或对用户输入作出反应,同时忙于执行您通过上一次按钮单击(或其他)触发的某种方法。



如果你想同时做多件事,你需要处理多线程。有各种方法可以做到这一点。我建议你使用(或多个)BackgroundWorker(因为这对初学者来说是一种简单的方法)。



假设您点击A按钮然后您的UI线程将执行按钮A单击的事件处理程序方法。在那里你会启动一个BackgroundWorker来进行实际搜索(或其他)。这将释放您的UI线程以恢复其主要目的,更新UI并对用户输入做出反应。然后,您可以单击B按钮启动另一个执行其他搜索(或其他)的BackgroundWorker。当BackgroundWorker完成后,它可以回调您的UI线程(使用另一个事件处理程序方法),以便在表单上显示结果。



有关使用BackgroundWorker的示例,请查看此处:

http://www.dotnetperls.com/progressbar [ ^ ]

http://stackoverflow.com/a/1068743/4320056 [ ^ ]

http://www.codeproject.com/Messages/5050414/Re-WinForms-Update-A-Dialog.aspx [ ^ ]



请试一试如果你不能让它工作,请随时在这里发布另一个问题并包含你的代码,以便我们可以看到问题所在。
First, please let me clarify one thing: A button-click or some other UI-interaction causes an event and the event causes your event-handler-method to be executed. So you don't "run the events".

If you do not implement some kind of multi-threading, then the UI-thread is the only thread running in your application-process - and it can only do one thing at a time. And as you probably already have noticed, it also can't update your UI or react to user-input while being busy with executing some method that you've triggered with a previous button-click (or whatever).

If you want to be able to do multiple things simultaneously, you need to deal with multi-threading. There are various ways to do that. I would recommend you to use a (or multiple) "BackgroundWorker" (because it's an easy way for a beginner).

Let's say you click button "A" then your UI-thread would execute the event-handler-method for "button A click". There you would start a BackgroundWorker that does the actual searching (or whatever). That frees your UI-thread to resume its main purpose, to update the UI and react to user input. Then you can click on button "B" to start another BackgroundWorker that does the other search (or whatever). When a BackgroundWorker finishes, it can call back to your UI-thread (with yet another event-handler-method) in order to display the result on your form.

For examples of using a BackgroundWorker please take a look here:
http://www.dotnetperls.com/progressbar[^]
http://stackoverflow.com/a/1068743/4320056[^]
http://www.codeproject.com/Messages/5050414/Re-WinForms-Update-A-Dialog.aspx[^]

Please give it a shot and if you can't get it to work, feel free to post another question here and include your code so we can see where the problem is.


这篇关于RUN两个不同形式的textbox.textchange事件一次性...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆