vb.net制作闹钟 vb程序设计时钟

利用vb.net实现小闹钟功能Private Declare Function mciSendStringA Lib "winmm.dll" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Function PlayMidiFile(ByVal MusicFile As String) As Boolean
If System.IO.File.Exists(MusicFile) Then
mciSendStringA("stop music", "", 0, 0)
mciSendStringA("close music", "", 0, 0)
mciSendStringA("open "MusicFile" alias music", "", 0, 0)
PlayMidiFile = mciSendStringA("play music", "", 0, 0) = 0
End If
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If TextBox1.Text = TimeOfDay Then
'具体提醒的东西,如你说的播放音乐
PlayMidiFile("自己添加路径")
End If
'时间格式要是这样的16:00:00
'timer的interval要设成1
'你还可以自己细化
End Sub
vb.net开发简单的时钟程序??高手救救我!就





Hand类的代码:
Public MustInherit Class Hand
Protected gp As GraphicsPath = New GraphicsPath()
Protected gpBase As GraphicsPath = Nothing
Protected midX As Integer = 150 ‘默认的窗体
Protected midY As Integer = 150 ‘中心位置
‘构造器 , 得到窗体中心位置
Public Sub New(ByVal theForm As Form1)
midX = (theForm.ClientRectangle.LefttheForm.ClientRectangle.Right) / 2
midY = (theForm.ClientRectangle.ToptheForm.ClientRectangle.Bottom) / 2
End Sub
MustOverride Sub Transform(ByVal d As DateTime)
‘绘制指针路径
Overridable Sub Draw(ByVal g As Graphics)
Dim aPen As Pen = New Pen(Brushes.Black, 4F)
g.DrawPath(aPen, gp)
g.FillPath(Brushes.Black, gp)
aPen.Dispose()
End Sub
‘使用矩阵实现路径(gp)的旋转
Public Sub Rotate(ByVal angle As Double)
gp = CType(gpBase.Clone(), GraphicsPath)
Dim mTransform As Matrix = New Matrix()
mTransform.RotateAt(CType(angle,Single),NewPointF(midX,midY))
gp.Transform(mTransform)
End Sub
End Class
为了节省篇幅,上面的代码省略了引入命名空间的语句 。
下面是分针(MinuteHand)类的定义:
Public Class MinuteHand
Inherits Hand
‘构造器,生成绘制分针的路径(gp)
Public Sub New(ByVal myForm As Form1)
MyBase.New(myForm)
gp.AddLine(midX, midY, midX, 45)
gp.AddLine(midX, 45, midX - 3, 50)
gp.AddLine(midX - 3, 50, midX3, 50)
gp.AddLine(midX3, 50, midX, 45)
gpBase = CType(gp.Clone(), GraphicsPath)
End Sub
‘Transform方法取得系统当前时间,并旋转时钟指针 。
Public Overrides Sub Transform(ByVal d As DateTime)
Dim minuteTime As Double = (CDbl(d.Minute)CDbl(d.Second / 60))
Dim angle As Double = (CDbl(minuteTime) / 60) * 360
Rotate(angle)
End Sub
End Class
对所有的指针旋转的方法都是相同的,因此在基类中实现 。由于时针和秒针的实现与分针相似,所不同者,只在于构造器中绘制的指针路径不同和Transform方法中转动的角度不同,在这里就不在赘述了 。
另外还需要提一下的是画时钟表面的代码 , 时钟表面用ClockFace类来实现 。这个类首先画一个圆代表时钟,然后画上米老鼠的图案,最后在相应的位置画上数字1~12代表12个小时 。
Public Sub Draw(ByVal g As Graphics)
DrawClockFace(g)
DrawImage(g)
DrawNumbers(g)
DrawPin(g)
End Sub
下面是ClockFace类的属性:
Private ClockRectangle As Rectangle
Private ClockFont As Font = New Font("Arial", 12)
Private midPoint As Point
Private ClockImage As Bitmap
Private Const IMAGEX As Integer = 50
Private Const IMAGEY As Integer = 50
DrawClockFace方法用来画时钟表面:
Private Sub DrawClockFace(ByVal g As Graphics)
g.FillEllipse(Brushes.White, ClockRectangle.Left10, ClockRectangle.Top10, ClockRectangle.Width - 20, ClockRectangle.Height - 20)
g.DrawEllipse(Pens.Black, ClockRectangle.Left10, ClockRectangle.Top10, ClockRectangle.Width - 20, ClockRectangle.Height - 20)
End Sub
然后用Graphics对象的DrawImage方法画出米老鼠的图片:
Private Sub DrawImage(ByVal g As Graphics)
Dim nWidth As Integer = ClockImage.Width
Dim nHeight As Integer = ClockImage.Height
Dim destRect As Rectangle = New Rectangle(midPoint.X - IMAGEX / 2, midPoint.Y - IMAGEY / 2, IMAGEX, IMAGEY)
g.DrawImage(ClockImage, destRect)
End Sub
数字在时钟上的位置是用sin和cos函数计算的:
Private Sub DrawNumbers(ByVal g As Graphics)
Dim count As Integer = 1
Dim a As Double
For a = 0 To 2 * Math.PI Step 2 * Math.PI / 12
Dim x As Double = (ClockRectangle.Width - 70) / 2 * Math.Cos(a - Math.PI / 3)(ClockRectangle.Width - 70) / 225
Dim y As Double = (ClockRectangle.Width - 70) / 2 * Math.Sin(a - Math.PI / 3)(ClockRectangle.Width - 70) / 220
g.DrawString(Convert.ToString(count), ClockFont, Brushes.Black, CType(x, Single), CType(y, Single), New StringFormat())
count= 1
Next
End Sub
最后是窗体文件(Form1.vb):
Public Class Form1
Inherits System.Windows.Forms.Form
Private MyMinuteHand As MinuteHand
Private MyHourHand As HourHand
Private MySecondHand As SecondHand
Private TheClockFace As ClockFace
Private FirstTick As Boolean = False
‘在窗体的OnPaint事件中取得Graphics对象
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If (FirstTick = False) Then Exit Sub
Dim g As Graphics = e.Graphics
TheClockFace.Draw(g)
MyHourHand.Draw(g)
MyMinuteHand.Draw(g)
MySecondHand.Draw(g)
TheClockFace.DrawPin(g)
End Sub
‘计时器事件
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MySecondHand.Transform(DateTime.Now)
MyHourHand.Transform(DateTime.Now)
MyMinuteHand.Transform(DateTime.Now)
FirstTick = True
Invalidate()
人求助关于VB编写小闹钟的程序 。修改完毕,并添加vb.net制作闹钟了注释
-------------------------------------------
Option Explicit
Dim AlarmTime '申明变量(这个样子定义变量行吗vb.net制作闹钟?是什么类型vb.net制作闹钟?)
'将AlarmTime申明为变体型(Variant)
Private Sub Command1_Click()
Call dialog '调用dialog子程序
End Sub
Private Sub Form_Load()
Command3.Enabled = False '初始化时command3为不可用vb.net制作闹钟的
AlarmTime = "" '(这样的话不就是当成字符串的形式了么?
'此时AlarmTime为字符串型(String)
End Sub
Private Sub Command2_Click()
'AlarmTime = InputBox("请输入你想设定的时间,例如(19:12:00)", "小闹钟").
AlarmTime = InputBox("请输入你想设定的时间,例如(19:12:00)", "小闹钟")
'此时AlarmTime为字符串型(String)
'If AlarmTime = "Then Exit Sub"
If AlarmTime = "" Then Exit Sub
If Not IsDate(AlarmTime) Then
MsgBox "你所输入的不是时间格式,请重试!", , "Wrong"
Else
AlarmTime = CDate(AlarmTime)
'此时AlarmTime为日期型(Date)
End If
'判断输入的是否可转换成time格式
'isdate函数是判断输入的是否可转换成date格式
End Sub
Private Sub Command3_Click()
Call deng
'调用deng子程序
End Sub
Private Sub Form_Click()
frmabout.Show
'显示关于对话框
End Sub
Private Sub Form_Resize()
If WindowState = 1 Then
Call mintime
Else
Caption = "小闹钟"
End If
'如果窗口被最小化,则调用mintime程序
End Sub
Private Sub mintime()
Caption = Format(Time, "long Time")
'使用长时间格式来显示时间
End Sub
Private Sub Timer1_Timer()
If lbltime.CaptionCStr(Time) Then
lbltime.Caption = Time
End If
'显示时间每秒钟的变化
If Time = AlarmTime Then
Call deng
End If
'判断如果现在的时间超过了设定的时间,则调用deng子程序
If WindowState = 1 Then
If Minute(CDate(Caption))Minute(Time) Then
mintime
End If
End If
'最小化时显示时间每分钟的变化
End Sub
Sub dialog()
CommonDialog1.Flags = cdlCFBoth
CommonDialog1.ShowOpen
Label1.Caption = CommonDialog1.FileName
'If Label1" Then
If Label1"" Then
Command3.Enabled = -1
Else
Exit Sub
End If
'把打开的文件名给于label1
'如果label1不为空时,则command3即可用
End Sub
Sub deng()
Dim ss
ss = Shell(Label1.Caption, 1)
End
'启动指定的文件,并且结束小闹钟程序
End Sub
怎样用vb.net作一个指针转动的钟表?(可设置时间日期,有闹铃功能)vb.net制作闹钟你需要会用GDI ,也就是那个System.Drawing命名空间下vb.net制作闹钟的类.
给你说个思路,设Timer,到时间就用Form.Invalidate()函数重画窗口,在重画窗口vb.net制作闹钟的Form_Paint事件下面编写代码得到当前时间,再根据当前时间用GDI 画时钟.
跪求用vb.net做一个小闹钟?。?/h2>'加个定时器,textbox ,button,labelPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Now
If FF = Now And FF"2001-1-1" And Timer1.Tag = "" Then
Timer1.Tag = "1"
MsgBox("ff")
End If
End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FF = TextBox1.Text
Timer1.Tag = ""
End SubPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FF = "2001-1-1"
End Sub'声音加个 AxMMControl控件AxMMControl1.DeviceType = "waveaudio" ''''''''定义播放*.wav格式AxMMControl1.FileName = "c:\1.wav" ''''''''载入文件 , AxMMControl1.Command = "open" ''''''''打开载入的文件
AxMMControl1.From = 0'从头开始
AxMMControl1.Command = "play"'保存时间,只要设定时把时间保存到文本文件就行,load 事件中读取,并对比是不是超时,.
【vb.net制作闹钟 vb程序设计时钟】vb.net制作闹钟的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于vb程序设计时钟、vb.net制作闹钟的信息别忘了在本站进行查找喔 。

    推荐阅读