由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - vb.net event handler 请教!如何raise一个event,所有form中任何一个on top的可以handle?
相关主题
a C# questionQuestion about struct
A permission problem?Q: Radiobuttonlist - select item in Datalist
问appSettingsLook for a reliable ajax framework
Event trackingKill running applications
microsoft .net event为什么我的vs2005不能打开Access文件
又一个教你怎么做GALLERY的请问可能从command line invoke复杂的Windows Form Application吗?
C# listview中的动态查找用Web Service,当client调用Server的API的时候,
Thread suspend and resume想破脑壳也不知道为什么finally不执行
相关话题的讨论汇总
话题: event话题: form话题: class话题: scanner话题: sub
进入DotNet版参与讨论
1 (共1页)
n*****3
发帖数: 15
1
新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一
个windowsCE版的application.我的工作是把它转成windows application will be
running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为
不同os系统。
app是这样的,main form只包括一些button, click the button to open secondary
level forms, these forms will handle the sanner event, and based on the data
input, 3rd level forms could be open from some point and handle scanner
event too.
main form will just initial scanner class, no data handler. the secondary
and third level form contain "Friend WithEvents" and a sub handles these
scanner data. every for has different way to process data.
当scanner event 发生,任何一个active的form(on the top)就要handle the scanned
data. event只能由scanner class to invoke a sub outside the scanner class to
raise.这部分只能这样不能改。原有的这个windowCE是work的,但是用的是Microsoft.
WindowsCE.Forms.MessageWindow, 转成windows app 就不能用了。我试过把scanner
event放在module里,在每个form里的sub form_load 加addhandler, 第一个form read
很好,但是这些forms开的多了,换来换去的,程序就因有太多激活的handler而死机。
所以这种方发不可行。
又试了写一个evntclass for raise the event, 用withevents和sub getdata()
handles evntclass.event 来handle.在scanner class里, 当scan发生,new一个
evntclass to raise this event, 但是在form class里根本接受不到这个event, 可能
是因为scannerclass new 的这个evntclass 和form里的evntclass是different copy
of evntclass, they cannot see each other. 这种方法只有raise event and handle
event方在一个class里才能work 是吗?
所以我又研究了一下原程序,他的方法用的是microsoft.WindowsCE.Forms.
MessageWindow来raise这个event,这样每个form都能看到这个event,从而可以handle
它.
每个form里有"Friend WithEvents event1 as new MsgWindow " 和 "sub getdata()
handles event1.raiseevent1".
in scanner class:
.....
if scan happens then
Dim msg As Microsoft.WindowsCE.Forms.Message = Microsoft.WindowsCE.Forms.
Message.Create(HWND_BROADCAST, WM_ManagedScan, IntPtr.Zero, IntPtr.Zero)
MessageWindow.SendMessage(msg)
end it
end class
----module for the event --------
Module modMessage
Public Class MsgWindow
Inherits microsoft.WindowsCE.Forms.MessageWindow

Public Event Event1(ByVal ScanData As String)
Protected Overrides Sub WndProc(ByRef msg As icrosoft.WindowsCE.
Forms.Message)
Select Case msg.Msg
RaiseEvent Event1(ScanData)
End Select
MyBase.WndProc(msg)
End Sub
End Class
我注意到他用create a msg and use MessageWindow.sendMessage(msg) method to
send it out to invoke Class MsgWindow's Overrides Sub WndProc, so the event
get to raised. that way, the event1 raised from messageWindow will be seeing
by every form in the app? why?
我的问提是:
1。这种方法raised的event就可以被所有form看到吗?为什么呢?
2。windows系统是否也有相似的功能?如果有,那么这部分code怎样转换成可以用于
windows app的呢?
请大侠们帮帮忙, 我这个新手实在想不出别的办法。网上搜索了很久了。万分感谢!!
v******n
发帖数: 421
2
ce 也是从 windows 移植过去的,WndProc 涉及到底层 win32 message处理了, 跟
VB 的 Event 不是一个概念
HWND_BROADCAST 给所有 top-level 窗口发消息
http://msdn.microsoft.com/en-us/library/windows/desktop/ms64495
我估计 System.Windows.Forms.Form 和你这里 CE 的 MessageWindow 对应

data

【在 n*****3 的大作中提到】
: 新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一
: 个windowsCE版的application.我的工作是把它转成windows application will be
: running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为
: 不同os系统。
: app是这样的,main form只包括一些button, click the button to open secondary
: level forms, these forms will handle the sanner event, and based on the data
: input, 3rd level forms could be open from some point and handle scanner
: event too.
: main form will just initial scanner class, no data handler. the secondary
: and third level form contain "Friend WithEvents" and a sub handles these

n*****3
发帖数: 15
3
新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一
个windowsCE版的application.我的工作是把它转成windows application will be
running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为
不同os系统。
app是这样的,main form只包括一些button, click the button to open secondary
level forms, these forms will handle the sanner event, and based on the data
input, 3rd level forms could be open from some point and handle scanner
event too.
main form will just initial scanner class, no data handler. the secondary
and third level form contain "Friend WithEvents" and a sub handles these
scanner data. every for has different way to process data.
当scanner event 发生,任何一个active的form(on the top)就要handle the scanned
data. event只能由scanner class to invoke a sub outside the scanner class to
raise.这部分只能这样不能改。原有的这个windowCE是work的,但是用的是Microsoft.
WindowsCE.Forms.MessageWindow, 转成windows app 就不能用了。我试过把scanner
event放在module里,在每个form里的sub form_load 加addhandler, 第一个form read
很好,但是这些forms开的多了,换来换去的,程序就因有太多激活的handler而死机。
所以这种方发不可行。
又试了写一个evntclass for raise the event, 用withevents和sub getdata()
handles evntclass.event 来handle.在scanner class里, 当scan发生,new一个
evntclass to raise this event, 但是在form class里根本接受不到这个event, 可能
是因为scannerclass new 的这个evntclass 和form里的evntclass是different copy
of evntclass, they cannot see each other. 这种方法只有raise event and handle
event方在一个class里才能work 是吗?
所以我又研究了一下原程序,他的方法用的是microsoft.WindowsCE.Forms.
MessageWindow来raise这个event,这样每个form都能看到这个event,从而可以handle
它.
每个form里有"Friend WithEvents event1 as new MsgWindow " 和 "sub getdata()
handles event1.raiseevent1".
in scanner class:
.....
if scan happens then
Dim msg As Microsoft.WindowsCE.Forms.Message = Microsoft.WindowsCE.Forms.
Message.Create(HWND_BROADCAST, WM_ManagedScan, IntPtr.Zero, IntPtr.Zero)
MessageWindow.SendMessage(msg)
end it
end class
----module for the event --------
Module modMessage
Public Class MsgWindow
Inherits microsoft.WindowsCE.Forms.MessageWindow

Public Event Event1(ByVal ScanData As String)
Protected Overrides Sub WndProc(ByRef msg As icrosoft.WindowsCE.
Forms.Message)
Select Case msg.Msg
RaiseEvent Event1(ScanData)
End Select
MyBase.WndProc(msg)
End Sub
End Class
我注意到他用create a msg and use MessageWindow.sendMessage(msg) method to
send it out to invoke Class MsgWindow's Overrides Sub WndProc, so the event
get to raised. that way, the event1 raised from messageWindow will be seeing
by every form in the app? why?
我的问提是:
1。这种方法raised的event就可以被所有form看到吗?为什么呢?
2。windows系统是否也有相似的功能?如果有,那么这部分code怎样转换成可以用于
windows app的呢?
请大侠们帮帮忙, 我这个新手实在想不出别的办法。网上搜索了很久了。万分感谢!!
v******n
发帖数: 421
4
ce 也是从 windows 移植过去的,WndProc 涉及到底层 win32 message处理了, 跟
VB 的 Event 不是一个概念
HWND_BROADCAST 给所有 top-level 窗口发消息
http://msdn.microsoft.com/en-us/library/windows/desktop/ms64495
我估计 System.Windows.Forms.Form 和你这里 CE 的 MessageWindow 对应

data

【在 n*****3 的大作中提到】
: 新手刚开始vb.net不到一年,event handler部分还很困惑。手头有一个project, 是一
: 个windowsCE版的application.我的工作是把它转成windows application will be
: running on win 7 os, 所有程序都不用改,只是event handler process 要改, 因为
: 不同os系统。
: app是这样的,main form只包括一些button, click the button to open secondary
: level forms, these forms will handle the sanner event, and based on the data
: input, 3rd level forms could be open from some point and handle scanner
: event too.
: main form will just initial scanner class, no data handler. the secondary
: and third level form contain "Friend WithEvents" and a sub handles these

1 (共1页)
进入DotNet版参与讨论
相关主题
想破脑壳也不知道为什么finally不执行microsoft .net event
请问.Net相关的工作,面试是什么风格的? 又一个教你怎么做GALLERY的
Re: payan, talk a little bit about rainbC# listview中的动态查找
how to make a vb module run in .net?Thread suspend and resume
a C# questionQuestion about struct
A permission problem?Q: Radiobuttonlist - select item in Datalist
问appSettingsLook for a reliable ajax framework
Event trackingKill running applications
相关话题的讨论汇总
话题: event话题: form话题: class话题: scanner话题: sub