An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
Private SubForm_Load() Timer1.Interval = 0 End Sub Private SubCommand1_Click() '手动 Timer1.Interval = 0 Call MyMove End Sub Private SubCommand2_Click() '自动 Timer1.Interval = 200 End Sub Private SubTimer1_Timer() Call MyMove End Sub SubMyMove() Label1.Move Label1.Left, Label1.Top + 50 If Label1.Top > Form1.Height Then Label1.Top = 0 End Sub
Dim step1 As Integer Private Sub Form_Load() step1 = 1 Timer1.Interval = 0 End Sub Private Sub Command1_Click()’自动 Timer1.Interval = 200 End Sub Private Sub Command2_Click() ‘手动 Timer1.Interval = 0 Call mymove End Sub Private Sub Timer1_Timer() Static flag As Boolean If flag Then Label1.ForeColor = &HFF44FF flag = Not flag Call mymove End Sub Public Sub mymove() Label1.Move Label1.Left + 50 * step1 If Label1.Left > Form1.Width Then step1 = -1 ElseIf Label1.Left < 0 Then step1 = 1 End If End Sub
2.事件、事件过程、事件驱动 • 事件:是VB预先设置的、能被对象可以响应或识别的用户操作或动作。它发生在用户与应用程序交互时。一个对象可识别和响应多个不同的事件。 • VB为对象预先定义了一系列的事件。例如,单击Click、获取焦点GotFocus 、按下键盘KeyPress 等。 • 同一事件,对不同的对象,会引发不同的反应: 学生_铃声() 听讲 End Sub 教师_铃声() 讲课 End Sub 其他人员_铃声() 可不于响应 End Sub
2.事件 • 事件过程:发生某事件后所要处理的步骤(即执行的程序代码)。针对某一对象的过程,与该对象的一个事件相联系 应用程序设计的主要工作就是为对象编写事件过程的代码。 • 事件过程的形式如下: Sub 对象名_事件(参数) …事件过程代码 End Sub 本章目录
模板产生 例:单击按钮 ,使Text1的字体为20磅. Sub Command1_Click() Text1.FontSize = 20 End Sub 一个动作可能同时发生多个事件。例如单击鼠标同时发生了: Click、MouseDown、MouseUp事件 编程时,只要对需要的事件过程编码。 注意:在代码窗,自动产生事件过程的模板,不要修改模板的内容,只需键入过程的代码。 用户输入 本章目录