一种方法 - 多事件 [英] One Method - Multiple Events

查看:88
本文介绍了一种方法 - 多事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一种方法处理多个事件。事件是KeyDown和SerialPort.PinChanged。

我的问题是这些事件有不同的签名。方法很简单如下:


Private Sub TextBox1_KeyDown(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyEventArgs)Handles TextBox1.KeyDown

---------------------------------

" Method的主体

---------------------------------

End Sub


任何建议?

谢谢

解决方案

为什么不简单地让两个事件程序都调用相同的Sub?


如果你有一个usercontrol并且需要在某个容器中可见的事件使用RaiseEvent并正确处理它们


CIao

我有2个我想要使用的事件。

KeyDown事件和SerialPort.PinChanged事件。

我的程序控制16个继电器并按预定顺序将它们切换多达125次。各种序列存储在一个数组中。

如果这是一个简单的过程,我只会复制它。我必须留在1个进程来维护序列。


我有2个与进程交互的事件。一个关键事件和通过串行端口输入---一个开关闭包。


正如我之前所说,KeyDown事件的签名与SerialPort.PinChanged事件的签名不同,所以这两个事件都可以不要叫同一个子。


还有其他想法吗?


I would like to handle multiple events with one method. The events are KeyDown and SerialPort.PinChanged.
My problem is that these events have different signatures. The method is simple as follows:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
---------------------------------
"The body of the Method
---------------------------------
End Sub

Any Suggestions?
Thanks

解决方案

Why not simply have both event procedures call the same Sub?


If you have on a usercontrol and need the events visible in some container use RaiseEvent and handle them properly

CIao


I have 2 events that I wish to use.
The KeyDown event and the SerialPort.PinChanged event.
My procedure controls 16 relays and toggles them up to 125 times in a predetermined sequence. Various sequences are stored in an Array.
If it were a simple procedure I would just duplicate it. I have to stay in the 1 process to maintain the sequence.

I have 2 events that interact with the process. A key event and an input through the Serial Port --- a switch closure.

As I said before the KeyDown Event has a different signature than the SerialPort.PinChanged Event so both events can''t call the same Sub.

Any other thoughts?


这篇关于一种方法 - 多事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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