用Visual Basic我们可设计出形形色色符合用户要求的应用程序,它确实是一种很好的用户程序开发工具,可VB提供的基本控件中都没有闪烁属性设置,使应用程序界面缺乏“活性”,近期笔者设计软件封面时,就要求字体不断地闪烁,为此,经反复分析、实践,最后终于成功地实现字体闪烁效果,现将设计过程说明如下: (1)创建一个新目标文件(project1),并建立一个窗体Form1。 (2)在Form1上配置一个计时器控制Timer1、标签控件Label1、命令控件Command1。 (3)各控件属性设置: Timer1的Enabled设置为True; Label1的Caption设置为需闪烁的字体:“江西省黎川县职业中专电脑室设计”、 Font设置字体及大小、Backstyle设置为“0-Transparent”; Command1中的Caption设置为“退出”。 (4)程序代码清单: Option Explicit Private Sub Form_ Load() Label1.Top=850 ′设置闪烁字体的显示位置 Label1.Left=750 Timer1.Interval=555 ′设置字体闪烁间隔时间 Form1.Windowstate=2 End Sub ′利用计时器控件Timer有规律地改变字体颜色(Forecolor) Private Sub Timer1_Timer() Chc Label1,1,4,8 End Sub ′Chc过程是循环地改变字体颜色(Forecolor) Sub Chc(Cont As Control,Color1 As Integer,Color2 As Integer,Color3 As Integer) If Val(Cont.Tag)=Color1 Then Cont.Tag=Color2 ElseIf Val(Cont.Tag)=Color2 Then
MouseDown、MouseUp、MouseMove。VB 似乎提供了很好的 Mouse 事件。但好象还缺少什么!对!还差 MouseExit(鼠标移出)事件。在 VB 中,我们要捕捉 MouseExit 事件,必须用 API 函数: Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long 然后,我们可以在控件(以 Picture1 为例)的 MouseMove 事件上加上以下代码: With Picture1 'Change this to the name of the control If Button = 0 Then If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then 'Mouse pointer is outside button, so let other controls receive 'mouseevents too: ReleaseCapture ' 放入鼠标离开的代码 Else ' Mouse pointer is over button, so we'll capture it, thus ' we'll receive mouse messages even if the mouse pointer is ' not over the button SetCapture .hwnd ' 放入鼠标进入的代码 End If