VB时钟控件练习

合集下载

VB2015编写时间小工具_倒顺计时_定时关机_闹钟等

VB2015编写时间小工具_倒顺计时_定时关机_闹钟等

PublicClass Form1Dim x, y, z AsBytePrivateSub Form1_Load(sender AsObject, e As EventArgs) HandlesMyBase.Loady = 0z = 0Dim thisDay AsInteger = Microsoft.VisualBasic.DateAndTime.Day(Now)'使用 Day 函数,可能需要用 Microsoft.VisualBasic 命名空间限定该函数,因为 System.Windows.Forms 命名空间将 Day 定义为枚举TextBox1.Text = 0TextBox2.Text = 0TextBox3.Text = 0TextBox5.Text = Year(Now)TextBox6.Text = Month(Now)TextBox7.Text = thisDayTextBox8.Text = Hour(Now)TextBox9.Text = Minute(Now)TextBox10.Text = Year(Now)TextBox11.Text = Month(Now)TextBox12.Text = thisDayTextBox13.Text = Hour(Now)TextBox14.Text = Minute(Now)EndSub'Private Sub AxMMControl1_BackClick(sender As Object, e As AxMCI.DmciEvents_BackClickEvent) Handles AxMMControl1.BackClick'使用COM有件中的:Microsoft Multimedia Contril (SP3) 音乐播放'End SubPrivateSub Button1_Click(sender AsObject, e As EventArgs) Handles Button1.ClickTimer1.Enabled = Truex = 1Button4.Enabled = FalseEndSubPrivateSub Button2_Click(sender AsObject, e As EventArgs) Handles Button2.Click'mand = "close" '使用COM有件中的:Microsoft Multimedia Contril (SP3) 音乐播放AxWindowsMediaPlayer1.close() ''使用COM有件中的Microsoft Media Player.这里是关闭播放x = 0EndSubPrivateSub Button3_Click(sender AsObject, e As EventArgs) Handles Button3.ClickOpenFileDialog1.InitialDirectory = "c:\"Dim result? AsBoolean = OpenFileDialog1.ShowDialog()If result = TrueThenTextBox4.Text = OpenFileDialog1.FileNameEndIf'AxMMControl1.FileName = TextBox4.Text '使用COM有件中的:Microsoft Multimedia Contril (SP3) 音乐播放EndSubPrivateSub Button4_Click(sender AsObject, e As EventArgs) Handles Button4.ClickTimer1.Enabled = Truex = 2Button1.Enabled = FalseEndSubPrivateSub Button5_Click(sender AsObject, e As EventArgs) Handles Button5.Clicky = 0x = 0z = 0TextBox1.Text = 0TextBox2.Text = 0TextBox3.Text = 0'mand = "close" '使用COM有件中的:Microsoft Multimedia Contril (SP3) 音乐播放 AxWindowsMediaPlayer1.close() ''使用COM有件中的Microsoft Media Player.这里是关闭播放 Button6.BackColor = Color.GoldButton6.ForeColor = Color.BlueButton6.Text = "启动"TextBox1.Enabled = TrueTextBox2.Enabled = TrueTextBox3.Enabled = TrueButton1.Enabled = TrueButton4.Enabled = TrueButton6.Enabled = TrueButton7.Enabled = TrueTextBox5.Enabled = TrueTextBox6.Enabled = TrueTextBox7.Enabled = TrueTextBox8.Enabled = TrueTextBox9.Enabled = TrueTextBox10.Enabled = TrueTextBox11.Enabled = TrueTextBox12.Enabled = TrueTextBox13.Enabled = TrueTextBox14.Enabled = TrueButton7.BackColor = Color.LimeButton7.ForeColor = Color.BlueButton7.Text = "启用"Label5.Text = "倒计时/顺计时时间:"Label5.ForeColor = Color.GreenEndSubPrivateSub Timer1_Tick(sender AsObject, e As EventArgs) Handles Timer1.TickIf x = 1 ThenTextBox1.Enabled = FalseTextBox2.Enabled = FalseTextBox3.Enabled = FalseLabel5.Text = "倒计时时间:"Label5.ForeColor = Color.RedIf TextBox1.Text <> 0 ThenTextBox1.Text -= 1EndIfIf (TextBox1.Text + TextBox2.Text + TextBox3.Text) <> 0 ThenIf TextBox1.Text = 0 ThenIf TextBox2.Text = 0 ThenTextBox1.Text = 60TextBox2.Text = 60TextBox3.Text -= 1EndIfIf TextBox2.Text <> 0 ThenTextBox1.Text = 60TextBox2.Text -= 1EndIfEndIfEndIfIf x = 1 Or x = 2 ThenIf (TextBox1.Text + TextBox2.Text + TextBox3.Text) = 0 ThenTimer1.Enabled = FalseTextBox1.Enabled = TrueTextBox2.Enabled = TrueTextBox3.Enabled = TrueButton1.Enabled = TrueButton4.Enabled = True'mand = "open" '使用COM有件中的:Microsoft Multimedia Contril (SP3) 音乐播放'mand = "play" '使用COM有件中的:Microsoft Multimedia Contril (SP3) 音乐播放AxWindowsMediaPlayer1.URL = TextBox4.Text '使用COM有件中的Microsoft Media Player.这里是播放的文件MsgBox("时间到!", 48, "提示!")Label5.Text = "倒计时/顺计时时间:"Label5.ForeColor = Color.GreenEndIfEndIfEndIfIf x = 2 ThenLabel5.Text = "顺计时时间:"Label5.ForeColor = Color.RedTextBox1.Enabled = FalseTextBox2.Enabled = FalseTextBox3.Enabled = FalseTextBox1.Text += 1If TextBox1.Text = 59 ThenTextBox1.Text = 0TextBox2.Text += 1If TextBox2.Text = 59 ThenTextBox2.Text = 0TextBox3.Text += 1EndIfEndIfEndIfEndSubPrivateSub Timer2_Tick(sender AsObject, e As EventArgs) Handles Timer2.TickDim a AsBytea = Weekday(Now)If a = 1 ThenLabel8.Text = "星期天"EndIfIf a = 2 ThenLabel8.Text = "星期一"EndIfIf a = 3 ThenLabel8.Text = "星期二"EndIfIf a = 4 ThenLabel8.Text = "星期三"EndIfIf a = 5 ThenLabel8.Text = "星期四"EndIfIf a = 6 ThenLabel8.Text = "星期五"EndIfIf a = 7 ThenLabel8.Text = "星期六"EndIfLabel6.Text = DateStringLabel7.Text = TimeStringDim thisDay AsInteger = Microsoft.VisualBasic.DateAndTime.Day(Now)If y = 1 ThenIf TextBox5.Text = Year(Now) ThenIf TextBox6.Text = Month(Now) ThenIf TextBox7.Text = thisDay ThenIf TextBox8.Text = Hour(Now) ThenIf TextBox9.Text = Minute(Now) Theny = 0Button7.BackColor = Color.LimeButton7.ForeColor = Color.BlueButton7.Text = "启用"Button7.Enabled = TrueTextBox5.Enabled = TrueTextBox6.Enabled = TrueTextBox7.Enabled = TrueTextBox8.Enabled = TrueTextBox9.Enabled = TrueAxWindowsMediaPlayer1.URL = TextBox4.Text MsgBox("闹钟时间到!", 48, "闹钟提示!") EndIfEndIfEndIfEndIfEndIfEndIfIf z = 1 ThenIf TextBox10.Text = Year(Now) ThenIf TextBox11.Text = Month(Now) ThenIf TextBox12.Text = thisDay ThenIf TextBox13.Text = Hour(Now) ThenIf TextBox14.Text = Minute(Now) Thenz = 0Button6.BackColor = Color.GoldButton6.ForeColor = Color.BlueButton6.Text = "启动"Button6.Enabled = TrueTextBox10.Enabled = TrueTextBox11.Enabled = TrueTextBox12.Enabled = TrueTextBox13.Enabled = TrueTextBox14.Enabled = TrueShell("shutdown.exe -f -s -t 3")'MsgBox("时间到!", 48, "错误提示!")EndIfEndIfEndIfEndIfEndIfEndIfEndSubPrivateSub TextBox1_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox1.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox2.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox1_LostFocus(sender AsObject, e As EventArgs) Handles TextBox1.LostFocusDim a AsStringa = Val(TextBox1.Text) 'Val'转换为数值型If TextBox1.Text <>""ThenIf a > 60 Or a < 0 ThenMsgBox("请输入正确的时间;0~60!", 48, "错误提示!")TextBox1.Focus() '重新获取焦点TextBox1.Text = ""EndIfEndIfEndSubPrivateSub TextBox2_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox2.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox3.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox2_LostFocus(sender AsObject, e As EventArgs) Handles TextBox2.LostFocusDim a AsStringa = Val(TextBox2.Text) 'Val'转换为数值型If TextBox2.Text <>""ThenIf a > 60 Or a < 0 ThenMsgBox("请输入正确的时间;0~60!", 48, "错误提示!")TextBox2.Focus() '重新获取焦点TextBox2.Text = ""EndIfEndSubPrivateSub TextBox3_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox3.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenButton1.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub Timer3_Tick(sender AsObject, e As EventArgs) Handles Timer3.TickEndSubPrivateSub Button6_Click(sender AsObject, e As EventArgs) Handles Button6.ClickDim a AsByteDim thisDay AsInteger = Microsoft.VisualBasic.DateAndTime.Day(Now)If Val(TextBox10.Text + TextBox11.Text + TextBox12.Text + TextBox13.Text + TextBox14.Text) >Val(Year(Now) & Month(Now) & thisDay & Hour(Now) & Minute(Now)) Thena = MsgBox("确认启用定时关机!", 305, "警示!")If a = vbOK Thenz = 1Button6.BackColor = Color.RedButton6.ForeColor = Color.BlackButton6.Text = "启动中"Button6.Enabled = FalseTextBox10.Enabled = FalseTextBox11.Enabled = FalseTextBox12.Enabled = FalseTextBox13.Enabled = FalseTextBox14.Enabled = FalseElsez = 0Button6.Enabled = TrueTextBox10.Enabled = TrueTextBox11.Enabled = TrueTextBox12.Enabled = TrueTextBox13.Enabled = TrueTextBox14.Enabled = TrueEndIfElseMsgBox("请输入正确的时间!", 48, "错误提示!")TextBox14.Focus() '重新获取焦点EndIfEndSubPrivateSub Button7_Click(sender AsObject, e As EventArgs) Handles Button7.ClickDim thisDay AsInteger = DateAndTime.Day(Now)If Val(TextBox5.Text + TextBox6.Text + TextBox7.Text + TextBox8.Text + TextBox9.Text) >Val(Year(Now) & Month(Now) & thisDay & Hour(Now) & Minute(Now)) Theny = 1MsgBox("请输入正确的时间!", 48, "错误提示!")TextBox9.Focus() '重新获取焦点EndIfIf y = 1 ThenButton7.BackColor = Color.CrimsonButton7.ForeColor = Color.BlackButton7.Text = "启用中"Button7.Enabled = FalseTextBox5.Enabled = FalseTextBox6.Enabled = FalseTextBox7.Enabled = FalseTextBox8.Enabled = FalseTextBox9.Enabled = FalseEndIfEndSub'Private Sub TextBox3_LostFocus(sender As Object, e As EventArgs) Handles TextBox3.LostFocus' Dim a As String' a = Val(TextBox3.Text) 'Val'转换为数值型' If TextBox3.Text <> "" Then' If a > 60 Or a < 0 Then' MsgBox("请输入正确的时间;0~60!", 48, "错误提示!")' TextBox3.Focus() '重新获取焦点' TextBox3.Text = ""' End If' End If'End SubPrivateSub TextBox5_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox5.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox6.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox5_LostFocus(sender AsObject, e As EventArgs) Handles TextBox5.LostFocusDim a AsStringa = Val(TextBox5.Text) 'Val'转换为数值型If TextBox5.Text <>""ThenIf a > 9999 Or a < Year(Now) ThenMsgBox("请输入正确的时间,当前年份~9999年!", 48, "错误提示!")TextBox5.Focus() '重新获取焦点TextBox5.Text = Year(Now)EndIfEndIfEndSubPrivateSub TextBox6_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox6.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox7.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox6_LostFocus(sender AsObject, e As EventArgs) Handles TextBox6.LostFocusDim a AsStringa = Val(TextBox6.Text) 'Val'转换为数值型If TextBox6.Text <>""ThenIf a > 12 Or a <= 0 ThenMsgBox("请输入正确的时间,1~12!", 48, "错误提示!")TextBox6.Focus() '重新获取焦点TextBox6.Text = Month(Now)EndIfEndIfEndSubPrivateSub TextBox7_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox7.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox8.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox7_LostFocus(sender AsObject, e As EventArgs) Handles TextBox7.LostFocusDim a AsStringDim thisDay AsInteger = DateAndTime.Day(Now)a = Val(TextBox7.Text) 'Val'转换为数值型If TextBox7.Text <>""ThenIf a > 31 Or a <= 0 ThenMsgBox("请输入正确的时间,1~31!", 48, "错误提示!")TextBox7.Focus() '重新获取焦点TextBox7.Text = thisDayEndIfEndIfEndSubPrivateSub TextBox8_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox8.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox9.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox8_LostFocus(sender AsObject, e As EventArgs) Handles TextBox8.LostFocusDim a AsStringDim thisDay AsInteger = DateAndTime.Day(Now)a = Val(TextBox8.Text) 'Val'转换为数值型If TextBox8.Text <>""ThenIf a > 23 Or a < 0 ThenMsgBox("请输入正确的时间,00~23!", 48, "错误提示!")TextBox8.Focus() '重新获取焦点TextBox8.Text = Hour(Now)EndIfEndIfEndSubPrivateSub TextBox9_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox9.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenButton7.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox9_LostFocus(sender AsObject, e As EventArgs) Handles TextBox9.LostFocusDim a AsStringDim thisDay AsInteger = DateAndTime.Day(Now)a = Val(TextBox9.Text) 'Val'转换为数值型If TextBox9.Text <>""ThenIf a > 59 Or a <= 0 ThenMsgBox("请输入正确的时间,00~59!", 48, "错误提示!")TextBox9.Focus() '重新获取焦点TextBox9.Text = Minute(Now)EndIfEndIfEndSubPrivateSub TextBox10_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox10.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox11.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox10_LostFocus(sender AsObject, e As EventArgs) Handles TextBox10.LostFocusDim a AsStringa = Val(TextBox10.Text) 'Val'转换为数值型If TextBox10.Text <>""ThenIf a > 9999 Or a < Year(Now) ThenMsgBox("请输入正确的时间,当前年份~9999年!", 48, "错误提示!")TextBox10.Focus() '重新获取焦点TextBox10.Text = Year(Now)EndIfEndIfEndSubPrivateSub TextBox11_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox11.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox12.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox11_LostFocus(sender AsObject, e As EventArgs) Handles TextBox11.LostFocusDim a AsStringa = Val(TextBox11.Text) 'Val'转换为数值型If TextBox11.Text <>""ThenIf a > 12 Or a <= 0 ThenMsgBox("请输入正确的时间,1~12!", 48, "错误提示!")TextBox11.Focus() '重新获取焦点TextBox11.Text = Month(Now)EndIfEndIfEndSubPrivateSub TextBox12_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox12.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox13.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox12_LostFocus(sender AsObject, e As EventArgs) Handles TextBox12.LostFocusDim a AsStringDim thisDay AsInteger = DateAndTime.Day(Now)a = Val(TextBox12.Text) 'Val'转换为数值型If TextBox12.Text <>""ThenIf a > 31 Or a <= 0 ThenMsgBox("请输入正确的时间,1~31!", 48, "错误提示!")TextBox12.Focus() '重新获取焦点TextBox12.Text = thisDayEndIfEndIfEndSubPrivateSub TextBox13_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox13.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing) If e.KeyChar = Chr(13) ThenTextBox14.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox13_LostFocus(sender AsObject, e As EventArgs) Handles TextBox13.LostFocusDim a AsStringDim thisDay AsInteger = DateAndTime.Day(Now)a = Val(TextBox13.Text) 'Val'转换为数值型If TextBox13.Text <>""ThenIf a > 23 Or a < 0 ThenMsgBox("请输入正确的时间,00~23!", 48, "错误提示!")TextBox13.Focus() '重新获取焦点TextBox13.Text = Hour(Now)EndIfEndIfEndSubPrivateSub TextBox14_KeyPress(sender AsObject, e As KeyPressEventArgs) Handles TextBox14.KeyPress Const xStr AsString = "0123456789"e.KeyChar = IIf(InStr(xStr & Chr(8) & Chr(13), e.KeyChar.ToString), e.KeyChar, Nothing)If e.KeyChar = Chr(13) ThenButton6.Focus()' Call Command1_Click 回车键事件,这里调用按键1内的单击事件EndIfEndSubPrivateSub TextBox14_LostFocus(sender AsObject, e As EventArgs) Handles TextBox14.LostFocus Dim a AsStringDim thisDay AsInteger = DateAndTime.Day(Now)a = Val(TextBox14.Text) 'Val'转换为数值型If TextBox14.Text <>""ThenIf a > 59 Or a <= 0 ThenMsgBox("请输入正确的时间,00~59!", 48, "错误提示!")TextBox14.Focus() '重新获取焦点TextBox14.Text = Minute(Now)EndIfEndIfEndSubEndClass。

最新vb常用控件--练习题(含答案)资料

最新vb常用控件--练习题(含答案)资料
Private Sub Form_Click()
For i = 1 to 6
List1.AddItem i
Next i
For i = 1 to 3
List1.RemoveItem i
Next i
End Sub
A)1,5,6 B)2,4,6 C)4,5,6 D)1,3,5
8.如果列表框List1中没有选定的项目,则执行
14.如果要每隔15s产生一个Timer事件,则Interval属性应设置为________。
A)15 B)900 C)15000 D)150
15.列表框的________属性是数组。
A)List和ListIndex B)List和ListCount
C)List和Selected D)List和Sorted
A)List1.List(List1.ListCount)B)List1.List(ListCount)
C)List1.List(List1.ListCount-1)D)List1.List(ListCount-1)
6.假如列表框List1有四个数据项,那么把数据项“China”添加到列表框的最后,应使用________语句。
1.下列控件中没有Caption属性的是________。
A)框架B)列表框C)复选框D)单选按钮
2.复选框的Value属性为1时,表示________。
A)复选框未被选中B)复选框被选中
C)复选框内有灰色的勾D)复选框操作有误
3.用来设置斜体字的属性是________。
A)FontItalic B)FontBold C)FontName D)FontSize
A)List1.AddItem 3,“China”

国家二级VB机试(常用标准控件)模拟试卷6(题后含答案及解析)

国家二级VB机试(常用标准控件)模拟试卷6(题后含答案及解析)

国家二级VB机试(常用标准控件)模拟试卷6(题后含答案及解析) 题型有:1. 选择题选择题1.设窗体上有一个标签Label1和一个计时器Timer1,Timer1的Interval 属性被设置为1000,Enabled属性被设置为True。

要求程序运行时每秒在标签中显示一次系统当前时间。

以下可以实现上述要求的事件过程是( )。

A.Private Sub Timer1_Timer( ) Lahel1.Caption=TreeEnd SubB.Private Sub Timer1_Timer( ) Label1.Caption=Time$End SubC.Private Sub Timer1_Timer( ) Label1.Interval=1End SubD.Private Sub Timer1_Timer( ) For k=1 To Timer1.Interval Label1.Caption=Timer Next kEnd Sub正确答案:B解析:Timer1的Interva1属性值是1000,Enabled 属性为True,说明定时器开始工作,每隔1000毫秒(即1秒)触发一次Timer事件,从而执行一次Timer 事件过程。

要想每秒在标签中显示一次系统时间,则在Timer事件过程中把系统时间赋给标签的Caption属性就能实现。

故选B。

知识模块:常用标准控件2.Visual Basic控件一般都规定一个默认属性,在引用这样的属性时,只写对象名而不必给出属性名。

默认属性为Caption的控件是( )。

A.列表框(ListBox)B.标签(Label)C.文本框(TextBox)D.组合框(ComboBox)正确答案:B解析:标签主要用来显示文本信息,它所显示的内容只能用Caption属性来设置或修改,Caption为标签控件的默认属性,引用时可以只写标签控件的对象名。

知识模块:常用标准控件3.决定标签内容显示位置的属性是( )。

用vb实现指针时钟的制作

用vb实现指针时钟的制作

用vb实现指针时钟的制作1、自定义坐标,让坐标原点在中心位置。

2、获取系统时间,使用函数time获取当前系统时间,而时、分、秒分别用以下函数Hour(Time)Minute(Time)Second(Time)可以用h,m,s三个变量分别存储系统当前的时、分、秒3、钟面的绘制,钟面上任意一点A的坐标A点坐标如下:X=ρcos(α)Y=ρsin(α)绘制钟面上的点3、指针的另一点的的x,y坐标的计算分析:若指针在第一象限,则B点坐标如下:X=ρcos(α)Y=ρsin(α)∵α+θ=π/2∴α=π/2 -θ∴x=ρCos(α)= ρcos(π/2 -θ)y=ρsin(α) =ρsin(π/2 -θ)若指针在第四象限,则有:∵α+θ=π/2+2π∴α=π/2+2π-θ又∵设α为任意角,终边相同的角的同一三角函数的值相等:sin(2kπ+α)= sinαcos(2kπ+α)= cosα∴x=ρcos(α)= ρcos(π/2+2π-θ)= ρcos(π/2 -θ) y=ρsin(α)= ρsin(π/2+2π-θ)= ρsin(π/2 -θ)同理,可以证明指针端点的坐标在二、三象限上也存在以下的关系:x=ρcos(π/2 -θ)y=ρsin(π/2 -θ)即对于时刻的指针端点的坐标均符合以下的表达式x=ρcos(π/2 -θ)y=ρsin(π/2 -θ)又∵秒针转动的角度值:θ=π/30*s∴秒针端点的坐标为x=ρcos(π/2 -π/30*s)y=ρsin(π/2 -π/30*s)同理,分针端点的坐标为x=ρcos(π/2 -π/30*m)y=ρsin(π/2 -π/30*m)同理,时针端点的坐标为x=ρcos(π/2 -π/6*s)y=ρsin(π/2 -π/6*s)。

巧用vb的TIMER控件

巧用vb的TIMER控件

Visual Basic提供一个Timer控件,其本质上是一个具有间隔时间设置所触发的时间程序,使我们可以将其隐藏在系统中,以某一时间间隔触发相关程序。

灵活地运用它可以取得很巧妙的效果。

下面,我们举一个例子。

我们可以在界面设计中设计出这样一种效果:一行文字在窗体中自左向右逐渐滚动,从右边“滚”出窗体的文字,又在左边逐渐出现。

如此循环下去。

类似电视上的滚动信息。

这样可使你设计的软件显得很生动,极易引起用户的兴趣。

其实,使用Visual Basic的Timer控件就可很容易地实现它。

首先,我们在窗体中设置两个Label控件Label1、Label2。

这两个控件中除Left属性外,其他属性设置成完全一样。

这主要是为了实现循环滚动的效果。

它们的Caption属性设置为要滚动显示的文字。

另外再调整好其字体、大小和颜色等。

在Form-Load过程中设置Label2.Left=-6240(窗体宽度),Label1.Left=0。

这样可保证La bel1的一部分“滚”出窗体,则Label2的一部分就进入窗体。

而形成循环滚动在窗体中设置?/FONT>Timer控件。

Timer控件的Interval属性决定滚动的速度,单位是毫秒。

例如,我们设置成300,则每隔0.3秒滚动一次。

然后,在Timer1-Timer()过程中加入如下程序:Private Sub Timer1-Timer()Label1.Left=Label1.Left+50Label2.Left=Label2.Left+50If Label1.Left>=6240 ThenLabel1.Left=-6240End IfIf Label2.Left>=6240 ThenLabel2.Left=6240End IfEnd Sub滚动效果就形成了,感兴趣的读者可以试试看。

只要灵活运用Timer控件,我们还可以设计出更有趣的效果。

如用Timer控件控制按钮控件的Visible属性,形成闪烁按钮。

VB常用控件习题参考答案-推荐下载

VB常用控件习题参考答案-推荐下载

对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术通关,1系电过,力管根保线据护敷生高设产中技工资术艺料0不高试仅中卷可资配以料置解试技决卷术吊要是顶求指层,机配对组置电在不气进规设行范备继高进电中行保资空护料载高试与中卷带资问负料题荷试2下ห้องสมุดไป่ตู้2,高总而中体且资配可料置保试时障卷,各调需类控要管试在路验最习;大题对限到设度位备内。进来在行确管调保路整机敷使组设其高过在中程正资1常料中工试,况卷要下安加与全强过,看度并22工且22作尽22下可22都能22可地护以缩1关正小于常故管工障路作高高;中中对资资于料料继试试电卷卷保破连护坏接进范管行围口整,处核或理对者高定对中值某资,些料审异试核常卷与高弯校中扁对资度图料固纸试定,卷盒编工位写况置复进.杂行保设自护备动层与处防装理腐置,跨高尤接中其地资要线料避弯试免曲卷错半调误径试高标方中高案资等,料,编试要5写、卷求重电保技要气护术设设装交备备置底4高调、动。中试电作管资高气,线料中课并敷3试资件且、设卷料中拒管技试试调绝路术验卷试动敷中方技作设包案术,技含以来术线及避槽系免、统不管启必架动要等方高多案中项;资方对料式整试,套卷为启突解动然决过停高程机中中。语高因文中此电资,气料电课试力件卷高中电中管气资壁设料薄备试、进卷接行保口调护不试装严工置等作调问并试题且技,进术合行,理过要利关求用运电管行力线高保敷中护设资装技料置术试做。卷到线技准缆术确敷指灵设导活原。。则对对:于于在调差分试动线过保盒程护处中装,高置当中高不资中同料资电试料压卷试回技卷路术调交问试叉题技时,术,作是应为指采调发用试电金人机属员一隔,变板需压进要器行在组隔事在开前发处掌生理握内;图部同纸故一资障线料时槽、,内设需,备要强制进电造行回厂外路家部须出电同具源时高高切中中断资资习料料题试试电卷卷源试切,验除线报从缆告而敷与采设相用完关高毕技中,术资要资料进料试行,卷检并主查且要和了保检解护测现装处场置理设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。

用VB制作一个动态时钟(转载)

用VB制作一个动态时钟(转载)

用VB制作一个动态时钟(转载)[原理]使用了LINE控件用来表示指针,根据粗细不同,分别为时、分、秒针,每个LINE都有2个点的坐标,一个点是原点,也就是表盘的最中心点,另一个点根据当前的时间计算从而决定。

然后通过TIMER控件,每隔1秒计算一次进行刷新,即可以实现。

[实现]一、新建立一个工程,在默认的窗体上添加以下三个LINE控件和一个TIMER控件,添加以下界面如下:二、在代码最上面建立全局变量,用于保存时钟原点:Dim x0 As SingleDim y0 As Single三、在窗体的FORM_LOAD事件中添加如下代码:Private Sub Form_Load()With Form1.Width = 3000.Height = 3100.BackColor = vbBlack.Caption = '动态时钟'End Withx0 = 1430y0 = 1290With Line1.X1 = x0.Y1 = y0End WithWith Line2.X1 = x0.Y1 = y0End WithWith Line3.X1 = x0.Y1 = y0End WithLine1.Visible = FalseLine2.Visible = FalseLine3.Visible = FalseLine1.BorderColor = vbRedLine2.BorderColor = vbRedLine3.BorderColor = vbRedEnd Sub四、在Timer的Timer事件中添加如下代码Private Sub Timer1_Timer()Text1.Text = DateLine1.Visible = TrueLine2.Visible = TrueLine3.Visible = TrueDim R0 As IntegerR0 = 1200R1 = 1000: R2 = 850: R3 = 600'画12个大圈子For i = 1 To 12X1 = x0 + R0 * Sin((i * 30) * 3.1415926 / 180)Y1 = y0 + R0 * Cos((i * 30) * 3.1415926 / 180)Circle (X1, Y1), 30, vbBlueNext i'画60个小圈子For i = 1 To 60X1 = x0 + R0 * Sin((i * 6) * 3.1415926 / 180)Y1 = y0 + R0 * Cos((i * 6) * 3.1415926 / 180)Circle (X1, Y1), 10, vbBlueNext i'秒针With Line1.X2 = x0 - R3 * Sin(-(Hour(Now) * 30 + Minute(Now) * 0.5) * 3.1415926 / 180).Y2 = y0 - R3 * Cos(-(Hour(Now) * 30 + Minute(Now) * 0.5) * 3.1415926 / 180)End With'分针With Line2.X2 = x0 - R2 * Sin(-(Minute(Now) * 6) * 3.1415926 / 180).Y2 = y0 - R2 * Cos(-(Minute(Now) * 6) * 3.1415926 / 180)End With'时针With Line3.X2 = x0 - R1 * Sin(-(Second(Now) * 6) * 3.1415926 / 180) .Y2 = y0 - R1 * Cos(-(Second(Now) * 6) * 3.1415926 / 180) End WithCircle (x0, y0), 20, vbWhiteEnd SubOK,至此大功告成,点击F5,就可以看到运行结果了。

vb常用控件--练习题(含答案)

vb常用控件--练习题(含答案)

1.下列控件中没有Caption属性的是________。

A)框架B)列表框C)复选框D)单选按钮2.复选框的Value 属性为1 时,表示________。

A)复选框未被选中B)复选框被选中C)复选框内有灰色的勾D)复选框操作有误3.用来设置斜体字的属性是________。

A)FontItalic B)FontBold C)FontName D)FontSize4.将数据项“China”添加到列表框List1中成为第二项应使用________语句。

A)List1.AddItem “China”,1 B)List1.AddItem “China ”, 2C)List1.AddItem 1,“China”D)List1.AddItem 2,“China ”5.引用列表框List1最后一个数据项,应使用________语句。

A)List1.List(List1.ListCount)B)List1.List(ListCount)C)List1.List(List1.ListCount-1)D)List1.List(ListCount-1)6.假如列表框List1有四个数据项,那么把数据项“China”添加到列表框的最后,应使用________语句。

A)List1.AddItem 3,“China ”B)List1.AddItem “China ”, List1.ListCount-1C)List1.AddItem “China ”, 3D)List1.AddItem “China”,List1.ListCount7.执行了下面的程序后,列表框中的数据项有________。

Private Sub Form_Click()For i = 1 to 6List1.AddItem iNext iFor i = 1 to 3List1.RemoveItem iNext iEnd SubA)1,5,6 B)2,4,6 C )4,5,6 D)1,3,58.如果列表框List1中没有选定的项目,则执行List1.RemoveItem List1.ListIndex 语句的结果是________。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

练习十五(时钟控件)
一、填空题
1、定时器(Timer)控件可识别的事件是__________,发生该事件的时间间隔由定时器的_________属性设置,其单位_________________。

2、某同学在窗体中放置了一个定时器控件。

并编了下列代码。

Private Sub Timer1_Timer()
Picture1.Left = Picture1.Left + 20
End Sub
但运行时图片Picture1不发生移动,请分析可能出错的原因。

_____________________________。

二、选择题
1、要将定时器控件的宽度设置增大一些,以下叙述正确的是()
A.设置定时器的Width B.设置定时器的Left属性
C.设置定器的Height属性D.无法对定时器的宽度进行设置。

2、将定时器的时间间隔设置为1秒,那么定时器的Interval属性值应设为()。

A.1000 B.1 C.100 D.10
3、设计动画时通常使用时钟()来控制动画速度。

A.Enabled B.Interval C.Timer D.Move
4、当设置了定时器的有关属性后,使窗体自动向下移动的语句是Move()。

A.Left,Top+100 B.Top+100 C.Top-100 D.Top=Top+100
三、写一个计时器程序,界面设计如下图所示,控件的属性如下表所示。

在单击“开始”按钮后,定时器开始计时,同时在标签Label1中显示“计时开始!”;当计时达到所选择的时间后停止计时,在标签Lable1中显示“时间到!”的字样。

程序运行时时默认的时间选择为10分钟。

请写出完成该程序功能的相应事件过程代码。

四、设计一个系统时钟。

程序运行后的界面如下图
所示;窗体上放置了4个Frame控件、2个标签
(Label1和Label2)、2个复选框(Check1和
Check2)、2个单选按钮(option1和option2)、
一个命令按钮(cmdExit)和1个Timer控件(Timer1)。

五、试制作小动画程序。

先在窗体上放一个标签
Label1,每过1秒标签Label1的背景颜色发生随机
变化,并自动修改标签的Left、Top属性使标签从
窗体的左上角向右下角移动,从而实现动画。

相关文档
最新文档