如何为窗体增加事件?

wuhee_snowwolf 招银网络科技(深圳) 研发部门经理  2003-01-07 06:12:57
由于我发现可以用Property语句为窗体增加属性,自然想到为窗体增加事件,但用Event语句定义后发现Form并不识别我定义的事件,而是将其作为一般过程处理。请问如何才能添加事件给窗体?
我的定义是:
Public Event ModeChange(Mode As Integer)
...全文
10 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuhee_snowwolf 2003-01-08
谢谢大家,我找到了,在MSDN里面使用跳转URL到
mk:@MSITStore:D:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1033\vbcon98.chm::/Html/vbconaddingeventtoform.htm
看 Adding an Event to a Form
回复
redwrite 2003-01-07
学习
回复
qxluo 2003-01-07

定义好事件后,在你的form中你认为该产生该事件的地方用

RaiseEvent ModeChange(mode)

触发

在其他模块中采用如下方式定义form就可以捕获事件了:

dim withevents form as frmYourFram

private sub form_modeChange(mode as Integer)
end sub
回复
litsnake1 2003-01-07
用raiseevent

Option Explicit

Private WithEvents mText As TimerState

Private Sub Command1_Click()
Text1.Text = "From Now"
Text1.Refresh
Text2.Text = "0"
Text2.Refresh
Call mText.TimerTask(9.84)
End Sub

Private Sub Form_Load()
Command1.Caption = "Click to Start Timer"
Text1.Text = ""
Text2.Text = ""
Label1.Caption = "The fastest 100 meters ever run took this long:"
Set mText = New TimerState
End Sub

Private Sub mText_ChangeText()
Text1.Text = "Until Now"
Text2.Text = "9.84"
End Sub

Private Sub mText_UpdateTime(ByVal dblJump As Double)
Text2.Text = Str(Format(dblJump, "0"))
DoEvents
End Sub

The remaining code is in a class module named TimerState. Included among the commands in this module are the Raise Event statements.

Option Explicit
Public Event UpdateTime(ByVal dblJump As Double)
Public Event ChangeText()

Public Sub TimerTask(ByVal Duration As Double)
Dim dblStart As Double
Dim dblSecond As Double
Dim dblSoFar As Double
dblStart = Timer
dblSoFar = dblStart

Do While Timer < dblStart + Duration
If Timer - dblSoFar >= 1 Then
dblSoFar = dblSoFar + 1
RaiseEvent UpdateTime(Timer - dblStart)
End If
Loop

RaiseEvent ChangeText

End Sub
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告