滚动字幕版代码
这个是我们老师做的,代码是对的,但放到有写机子上无法运行
滚动字幕版
窗体1
Dim intSpeed As Integer
Const strPrompt1 As String = "开往北京方向的66次列车马上就要开车了"
Const strPrompt2 As String = "神舟飞船,载誉归来~~~" Const strPrompt3 As String = "东方明珠,开盘价20元/股" Const strPrompt4 As String = "宝剑锋从磨砺出,梅花香自苦寒来"
Const strPrompt5 As String = "欲穷千里目,更上一层楼" Const strPrompt6 As String = "No Pay, no Gain"
Const strPrompt7 As String = "书山有路勤为径,学海无涯苦作舟"
Const strPrompt8 As String = "团结起来,共同战胜“非典”~"
Dim blnDirection As Boolean 'False 表示从右往左移动 True 表示从左往右移动
Dim blnAutoShift As Boolean 'True 表示左右摆动, False表示从左往右或从右往左
Dim blnShiftDirection As Boolean ' True 表示向左摆动, False
表示向右摆动
Dim blnShiftMode As Boolean ' True表示摆动方式一, False 表示摆动方式二
Dim blnStopMode As Boolean ' True表示暂停摆动,False表示继续摆动
Private Sub BKColor_Click()
Dim intColor1 As Long
Select Case BKColor.ListIndex
Case 0
intColor1 = vbBlack
Case 1
intColor1 = vbGreen
Case 2
intColor1 = vbBlue
Case 3
intColor1 = vbCyan
Case 4
intColor1 = vbRed
Case 5
intColor1 = vbYellow
Case 6
intColor1 = vbMagenta
Case 7
intColor1 = vbWhite
End Select
BKColor.Text = BKColor.Text
Form2.BackColor = intColor1
End Sub
Private Sub Check1_Click()
If Check1.Value = 1 Then
Frame1.Visible = True
Else
Frame1.Visible = False
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
Frame2.Visible = True
Else
Frame2.Visible = False
End If
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then
Frame4.Visible = True
Else
Frame4.Visible = False
End If
End Sub
Private Sub Check4_Click()
If Check4.Value = 1 Then
Timer3.Enabled = True
Else
Timer3.Enabled = False
End If
End Sub
Private Sub Check5_Click()
If Check5.Value = 1 Then
Form2.Label1.FontSize = 72
Form2.Label1.Top = (Form2.ScaleHeight -
Form2.Label1.Height) / 1
Form2.WindowState = 2
Timer1.Enabled = True
Else
Form2.Label1.Top = (Form2.ScaleHeight -
Form2.Label1.Height) / 1
Form2.WindowState = 0
Form2.Label1.FontSize = 24
End If
End Sub
Private Sub Command1_Click()
If Command1.Caption = "暂停" Then
Command1.Caption = "继续"
Timer1.Enabled = False
blnStopMode = True
Else
Command1.Caption = "暂停"
Timer1.Enabled = True
blnStopMode = False
End If
End Sub
Private Sub Command10_Click()
Form2.Label1.Caption = strPrompt7
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command11_Click()
Form2.Label1.Caption = strPrompt8
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command12_Click()
Me.Hide
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
Form2.Label1.Caption = strPrompt1
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command4_Click()
Form2.Label1.Caption = strPrompt4
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command5_Click()
Form2.Label1.Caption = strPrompt3
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command6_Click()
Form2.Label1.Caption = strPrompt2
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command7_Click()
Form_Load
End Sub
Private Sub Command8_Click()
Form2.Label1.Caption = strPrompt5
Form2.Label1.Left = (Form1.ScaleWidth - Form2.Label1.Width) / 2
End Sub
Private Sub Command9_Click()
Form2.Label1.Caption = strPrompt6
Form2.Label1.Left = (Form1.ScaleWidth -
Form2.Label1.Width) / 2
End Sub
Private Sub FGColor_Click()
Dim intColor1 As Long
Select Case FGColor.ListIndex
Case 0
intColor1 = vbBlack
Case 1
intColor1 = vbGreen
Case 2
intColor1 = vbBlue
Case 3
intColor1 = vbCyan
Case 4
intColor1 = vbRed
Case 5
intColor1 = vbYellow
Case 6
intColor1 = vbMagenta
Case 7
intColor1 = vbWhite
End Select
Form2.Label1.ForeColor = intColor1 End Sub
Private Sub Form_DblClick()
Check5.Value = 0
Check5_Click
End Sub
Private Sub Form_Load()
Form2.Show
intSpeed = 20
Option2_Click
BKColor.ListIndex = 1
FGColor.ListIndex = 6
Form2.Label1.Left = (Form2.ScaleWidth -
Form2.Label1.Width) / 2
Form2.Label1.Caption = strPrompt5
blnDirection = True ' 表示从右往左移动
blnAutoShift = False ' 表示单一方向移动
blnShiftDirection = True '一开始向左摆动
blnShiftMode = True '一开始选择摆动方式一
blnStopMode = False '一开始工作于可以摆动的状态
Check4.Value = 0 '一开始颜色手动控制
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer,
X As Single, Y As Single)
If Button = 2 Then
PopupMenu mnuPopupMenu
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y
As Single)
End Sub
Private Sub Frame2_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Frame4_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Frame5_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub HScroll1_Change()
intSpeed = HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
HScroll1_Change
End Sub
Private Sub mnuExit_Click()
End Sub
Private Sub mnuFileExit_Click()
Command2_Click
End Sub
Private Sub mnuFontSize12_Click()
Form2.Label1.FontSize = 12 End Sub
Private Sub mnuFontSize128_Click()
Form2.Label1.FontSize = 128 End Sub
Private Sub mnuFontSize24_Click()
Form2.Label1.FontSize = 24
End Sub
Private Sub mnuFontSize36_Click()
Form2.Label1.FontSize = 36 End Sub
Private Sub mnuFontSize48_Click()
Form2.Label1.FontSize = 48 End Sub
Private Sub mnuFontSize64_Click()
Form2.Label1.FontSize = 64 End Sub
Private Sub mnuFontSize72_Click()
Form2.Label1.FontSize = 72 End Sub
Private Sub mnuFontSize96_Click()
Form2.Label1.FontSize = 96 End Sub
Private Sub Option1_Click()
Form2.Label1.FontSize = 48 End Sub
Private Sub Option10_Click()
blnAutoShift = True ' 进行左右摆动
blnShiftMode = False ' 左右摆动方式二
Timer1.Enabled = False
Timer2.Enabled = True End Sub
Private Sub Option2_Click()
Form2.Label1.FontSize = 24 End Sub
Private Sub Option3_Click()
On Error GoTo l
Form2.Label1.FontName = "宋体"
Exit Sub
l:
MsgBox "对不起,本机无此字体。", vbInformation, "滚动字幕板"
End Sub
Private Sub Option4_Click()
On Error GoTo l
Form2.Label1.FontName = "隶书"
Exit Sub
l:
MsgBox "对不起,本机无此字体。", vbInformation, "滚动字幕板"
End Sub
Private Sub Option5_Click()
On Error GoTo l
Form2.Label1.FontName = "楷体_GB2312"
Exit Sub
l:
MsgBox "对不起,本机无此字体。", vbInformation, "滚动字
幕板"
End Sub
Private Sub Option6_Click()
On Error GoTo l
Form2.Label1.FontName = "黑体"
Exit Sub
l:
MsgBox "对不起,本机无此字体。", vbInformation, "滚动字幕板"
End Sub
Private Sub Option7_Click()
blnDirection = True
blnAutoShift = False
Timer2.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Option8_Click()
blnDirection = False
blnAutoShift = False
Timer2.Enabled = False
Timer1.Enabled = True End Sub
Private Sub Option9_Click()
blnAutoShift = True ' 进行左右摆动
blnShiftMode = True ' 左右摆动方式一
Timer1.Enabled = False
Timer2.Enabled = True End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = vbKeyReturn Then
Form2.Label1.Caption = Text1.Text
End If
End Sub
Private Sub Timer1_Timer()
If Not blnAutoShift Then '表示单一方向移动
If blnDirection Then
If Form2.Label1.Left + Form2.Label1.Width > 0 Then
Form2.Label1.Left = Form2.Label1.Left - intSpeed
Else
Form2.Label1.Left = Form1.ScaleWidth
End If
Else
If Form2.Label1.Left < Form2.ScaleWidth Then
Form2.Label1.Left = Form2.Label1.Left + intSpeed
Else
Form2.Label1.Left = -Form2.Label1.Width
End If
End If
End If
End Sub
Private Sub Timer2_Timer()
If Not blnStopMode Then
' 左右摆动的第一种方式
If blnShiftMode Then
If blnShiftDirection Then
If Form2.Label1.Left + Form2.Label1.Width > 0
Then
Form2.Label1.Left = Form2.Label1.Left - intSpeed
Else
blnShiftDirection = False
End If
Else
If Form2.Label1.Left < Form2.ScaleWidth Then
Form2.Label1.Left = Form2.Label1.Left +
intSpeed
Else
blnShiftDirection = True
End If
End If
Else
' 左右摆动的第二种方式
If blnShiftDirection Then
If Form2.Label1.Left > 0 Then
Form2.Label1.Left = Form2.Label1.Left - intSpeed
Else
blnShiftDirection = False
End If
Else
If Form2.Label1.Left + Form2.Label1.Width <
Form2.ScaleWidth Then
Form2.Label1.Left = Form2.Label1.Left +
intSpeed
Else
blnShiftDirection = True
End If
End If
End If
End If
End Sub
Private Sub Timer3_Timer()
Randomize
Form2.Label1.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Form2.BackColor = Not Form2.Label1.ForeColor And vbWhite End Sub
窗体2
Option Explicit
Private Sub Form_DblClick()
Form1.Show
End Sub
相关图片