重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
首先在form1上建立三个命令按钮,分别为command1(打开预启动的文件);command2(设定时间的按钮);第三个command3(即可启动)按钮可有可无;一个label1用来显示你预打开的文件名的路径;一个lbltime用来显示现在的时间;还有一个commondialog,它在工程菜单的部件中,你可把它加到工具箱中再开始使用;关于对话框你不必自己建,只要从应用程序向导中添加即可;一个timer,它的interval=500。 其次在form1的属性中设置为:startupposition=2-centerscreen和maxbutton=false;label1的属性中设置为:alignment=2-center。 外观大致是如图所示: 下面我们开始编程: OptionExplicit DimAlarmTime '申明变量 --------- PrivateSubCommand1_Click() Calldialog '调用dialog子程序 EndSub -------- PrivateSubCommand2_Click() AlarmTime=InputBox(“请输入你想设定的时间,例如(19:12:00)",“小闹钟") IfAlarmTime=“"ThenExitSub IfNotIsDate(AlarmTime)Then MsgBox“你所输入的不是时间格式,请重试!",,“Wrong" Else AlarmTime=CDate(AlarmTime) EndIf '判断输入的是否可转换成time格式 'isdate函数是判断输入的是否可转换成date格式 EndSub -------------- PrivateSubCommand3_Click() Calldeng '调用deng子程序 EndSub --------------- PrivateSubForm_Click() frmAbout.Show '显示关于对话框 EndSub ------------- PrivateSubForm_Load() Command3.Enabled=0 AlarmTime=“" '初始化时command3为不可用的 EndSub --------------- PrivateSubForm_Resize() IfWindowState=1Then mintime else caption=“小闹钟" EndIf '如果窗口被最小化,则调用mintime程序 EndSub --------------- PrivateSubmintime() Caption=Format(Time,“longTime") '使用长时间格式来显示时间 EndSub --------------- PrivateSubTimer1_Timer() IflblTime.CaptionCStr(Time)Then lblTime.Caption=Time EndIf '显示时间每秒钟的变化 IfTime=AlarmTimeThen Calldeng EndIf '判断如果现在的时间超过了设定的时间,则调用deng子程序 IfWindowState=1Then IfMinute(CDate(Caption))Minute(Time)Then mintime EndIf EndIf '最小化时显示时间每分钟的变化 EndSub ------------- Subdialog() CommonDialog1.Flags=cdlCFBoth CommonDialog1.ShowOpen Label1.Caption=CommonDialog1.filename IfLabel1“"Then Command3.Enabled=-1 Else ExitSub EndIf '把打开的文件名给于label1 '如果label1不为空时,则command3即可用 EndSub -------------- Subdeng() Dimss ss=Shell(Label1.Caption,1) End '启动指定的文件,并且结束小闹钟程序 EndSub 最后在about对话框中要提的是:在form_load中app.title表示你的应用程序的名字;app.major、minor、revision是关于应用程序的版本信息;lblDescription.Caption用于对本程序的一些说明描述之类的话;lblDisclaimer.Caption用于版权信息或警告等。 好了,至此我们已完成了一个简单的VB程序的编写,希望你能设计出更好的闹钟程序来!
成都创新互联成立于2013年,我们提供高端网站建设、成都网站制作、成都网站设计公司、网站定制、营销型网站、微信平台小程序开发、微信公众号开发、seo优化服务,提供专业营销思路、内容策划、视觉设计、程序开发来完成项目落地,为展览展示企业提供源源不断的流量和订单咨询。
vb中获取系统当前的时间用函数 now() 就可以。另外还有相关的时间 date() time()
now()获取系统当前日期和时间,如:2015-12-12 22:23:34
time()获取系统的时间,如:22:23:34不显示当前日期
date()获得系统的日期,如:2015-12-12
Private Sub Command1_Click()
MsgBox Now()
MsgBox Time()
MsgBox Date
End Sub
还要设置Format 为 : Custom
用的时候用DateTimePicker1.Text 不要用value
下面是我随便用了两个DateTimePicker和一个button一个textbox演示了一下的代码,你根据自己的需要调试DateTimePicker风格
------------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
#Region
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents DateTimePicker2 As System.Windows.Forms.DateTimePicker
System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.DateTimePicker2 = New System.Windows.Forms.DateTimePicker
Me.SuspendLayout()
'
'DateTimePicker1
'
Me.DateTimePicker1.AllowDrop = True
Me.DateTimePicker1.CustomFormat = "yyyy-MM-dd"
Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker1.Location = New System.Drawing.Point(56, 24)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.ShowUpDown = True
Me.DateTimePicker1.Size = New System.Drawing.Size(160, 19)
Me.DateTimePicker1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(144, 128)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(136, 72)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = "TextBox1"
'
'DateTimePicker2
'
Me.DateTimePicker2.CustomFormat = "yyyy-MM-dd"
Me.DateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker2.Location = New System.Drawing.Point(40, 160)
Me.DateTimePicker2.Name = "DateTimePicker2"
Me.DateTimePicker2.Size = New System.Drawing.Size(120, 19)
Me.DateTimePicker2.TabIndex = 3
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.DateTimePicker2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = DateTimePicker1.Text
End Sub
End Class
----------------------------------------------------------
我的操作系统和.net都是日文的,注释的东西我删除了,主要看代码就好了
这段代码你可以建一个空的解决方案,完全复制到里面去