主题:抱歉我是vb初學者~快要考試了可是我有三題一直做不出來~希望各位高手可以教教我~!
khfcfbi
[专家分:0] 发布于 2010-08-31 07:19:00
1. 請在畫面出現5張動物圖片(圖片自行設定),當滑鼠滑進圖片時會出現動物
的叫聲,並於畫面中出現動物的中文及英文名稱,當滑鼠離開圖片,就停止
叫聲,動物的中文及英文名稱消失。
2. 設計跑馬燈程式,畫面中出現”凡走過必將留下痕跡”,畫面中出現功能表,
有[方向]及[顏色]兩大項,[方向]中有[由右向左]、[由左向右]及[停止]等3小
項,[顏色]有[黑色字][紅色字]及[綠色字]3小項。
3. 設計一個使用者可以輸入英文姓名及電話號碼的程式,程式會檢查姓名只能
輸入A-Z及a-z和退位鍵,檢查電話號碼只能輸入0-9、(、)、-、#和退位鍵。
就是這三題一直做不出來~我知道可能對很多人來說很簡單~但我剛學一個月~對我來說有點困難~有高手可以麻煩指導我一下嗎??
回复列表 (共5个回复)
沙发
一江秋水 [专家分:9680] 发布于 2010-09-01 07:26:00
先做第一題吧。
這需要用到API函數,代碼如下:
Option Explicit
'获取鼠标指针的当前位置
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'返回指定点的窗口句柄
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
'播放音乐
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Timer1.Interval = 100
Picture1.Picture = LoadPicture("D:\Image\dog.jpg")
Picture2.Picture = LoadPicture("D:\Image\pig.jpg")
Picture3.Picture = LoadPicture("D:\Image\ox.jpg")
Picture4.Picture = LoadPicture("D:\Image\sheep.jpg")
Picture5.Picture = LoadPicture("D:\Image\horse.jpg")
Picture1.ToolTipText = "狗(dog)"
Picture2.ToolTipText = "猪(pig)"
Picture3.ToolTipText = "牛(ox)"
Picture4.ToolTipText = "羊(sheep)"
Picture5.ToolTipText = "马(horse)"
End Sub
Private Sub Timer1_Timer()
Dim p As POINTAPI, hwnd As Long
'sndPlaySound 0, 0
GetCursorPos p
hwnd = WindowFromPoint(p.x, p.y)
Select Case hwnd
Case Picture1.hwnd: sndPlaySound "D:\sound\dog.wav", 3
Case Picture2.hwnd: sndPlaySound "D:\sound\pig.wav", 3
Case Picture3.hwnd: sndPlaySound "D:\sound\ox.wav", 3
Case Picture4.hwnd: sndPlaySound "D:\sound\sheep.wav", 3
Case Picture5.hwnd: sndPlaySound "D:\sound\horse.wav", 3
End Select
End Sub
板凳
一江秋水 [专家分:9680] 发布于 2010-09-01 17:53:00
再做第二題
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3180
ClientLeft = 60
ClientTop = 360
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3180
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Left = 4080
Top = 2040
End
Begin VB.Frame Frame2
Caption = "顏色"
Height = 1815
Left = 2280
TabIndex = 3
Top = 1080
Width = 1695
Begin VB.OptionButton Option2
Caption = "綠色字"
Height = 180
Index = 2
Left = 120
TabIndex = 8
Top = 1320
Width = 1335
End
Begin VB.OptionButton Option2
Caption = "紅色字"
Height = 180
Index = 1
Left = 120
TabIndex = 7
Top = 840
Width = 1335
End
Begin VB.OptionButton Option2
Caption = "黑色字"
Height = 180
Index = 0
Left = 120
TabIndex = 6
Top = 360
Value = -1 'True
Width = 1335
End
End
Begin VB.Frame Frame1
Caption = "方向"
Height = 1815
Left = 240
TabIndex = 1
Top = 1080
Width = 1575
Begin VB.OptionButton Option1
Caption = "停止"
Height = 255
Index = 2
Left = 120
TabIndex = 5
Top = 1320
Width = 1215
End
3 楼
一江秋水 [专家分:9680] 发布于 2010-09-01 17:54:00
Begin VB.OptionButton Option1
Caption = "由左向右"
Height = 255
Index = 1
Left = 120
TabIndex = 4
Top = 840
Width = 1335
End
Begin VB.OptionButton Option1
Caption = "由右向左"
Height = 255
Index = 0
Left = 120
TabIndex = 2
Top = 360
Value = -1 'True
Width = 1335
End
End
Begin VB.Label Label1
Caption = "凡走過必將留下痕跡"
BeginProperty Font
Name = "宋体"
Size = 24
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 615
Left = 0
TabIndex = 0
Top = 120
Width = 4575
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0, 1: Timer1.Enabled = True
Case 2: Timer1.Enabled = False: Label1.Left = 0
End Select
End Sub
Private Sub Option2_Click(Index As Integer)
Select Case Index
Case 0: Label1.ForeColor = 0
Case 1: Label1.ForeColor = &H80&
Case 2: Label1.ForeColor = &H4000&
End Select
End Sub
Private Sub Timer1_Timer()
Select Case True
Case Option1(0).Value: Label1.Left = IIf(Label1.Left <= -Label1.Width, Width, Label1.Left - 60)
Case Option1(1).Value: Label1.Left = IIf(Label1.Left >= Width, -Label1.Width, Label1.Left + 60)
End Select
End Sub
說明:
1.這一題所用的控件多一點,所以要發窗體代碼,你復制到記事本文檔后保存為Form1.frm,再新建一個工程,用添加現存窗體的方式加到工程中。
2.如果用文本框替代標簽,移動時就不會那么閃
3.我是用改變標簽的Left屬性的辦法達到走馬燈效果,你也可以使用字符刪替的辦法達到同一目的,但視覺效果不一樣,你可以自己試一試
4 楼
老大徒伤悲 [专家分:29120] 发布于 2010-09-04 14:24:00
现在考试?不会补考吧?
5 楼
gfan [专家分:60] 发布于 2010-10-28 22:58:00
承接各种编程项目,主要语言包括Delphi,VC,VB,asp 如有需要请加Q: 383147818 注明: pfan项目
承接各种编程项目,主要语言包括Delphi,VC,VB,asp 如有需要请加Q: 383147818 注明: pfan项目
我来回复