首先在form1上建立三個(gè)命令按鈕,分別為command1(打開預(yù)啟動的文件);command2(設(shè)定時(shí)間的按鈕);第三個(gè)command3(即可啟動)按鈕可有可無;一個(gè)label1用來顯示你預(yù)打開的文件名的路徑;一個(gè)lbltime用來顯示現(xiàn)在的時(shí)間;還有一個(gè)commondialog,它在工程菜單的部件中,你可把它加到工具箱中再開始使用;關(guān)于對話框你不必自己建,只要從應(yīng)用程序向?qū)е刑砑蛹纯?一個(gè)timer,它的interval=500。 其次在form1的屬性中設(shè)置為:startupposition=2-centerscreen和maxbutton=false;label1的屬性中設(shè)置為:alignment=2-center。 外觀大致是如圖所示: 下面我們開始編程: OptionExplicit DimAlarmTime '申明變量 --------- PrivateSubCommand1_Click() Calldialog '調(diào)用dialog子程序 EndSub -------- PrivateSubCommand2_Click() AlarmTime=InputBox(“請輸入你想設(shè)定的時(shí)間,例如(19:12:00)",“小鬧鐘") IfAlarmTime=“"ThenExitSub IfNotIsDate(AlarmTime)Then MsgBox“你所輸入的不是時(shí)間格式,請重試!",,“Wrong" Else AlarmTime=CDate(AlarmTime) EndIf '判斷輸入的是否可轉(zhuǎn)換成time格式 'isdate函數(shù)是判斷輸入的是否可轉(zhuǎn)換成date格式 EndSub -------------- PrivateSubCommand3_Click() Calldeng '調(diào)用deng子程序 EndSub --------------- PrivateSubForm_Click() frmAbout.Show '顯示關(guān)于對話框 EndSub ------------- PrivateSubForm_Load() Command3.Enabled=0 AlarmTime=“" '初始化時(shí)command3為不可用的 EndSub --------------- PrivateSubForm_Resize() IfWindowState=1Then mintime else caption=“小鬧鐘" EndIf '如果窗口被最小化,則調(diào)用mintime程序 EndSub --------------- PrivateSubmintime() Caption=Format(Time,“l(fā)ongTime") '使用長時(shí)間格式來顯示時(shí)間 EndSub --------------- PrivateSubTimer1_Timer() IflblTime.CaptionCStr(Time)Then lblTime.Caption=Time EndIf '顯示時(shí)間每秒鐘的變化 IfTime=AlarmTimeThen Calldeng EndIf '判斷如果現(xiàn)在的時(shí)間超過了設(shè)定的時(shí)間,則調(diào)用deng子程序 IfWindowState=1Then IfMinute(CDate(Caption))Minute(Time)Then mintime EndIf EndIf '最小化時(shí)顯示時(shí)間每分鐘的變化 EndSub ------------- Subdialog() CommonDialog1.Flags=cdlCFBoth CommonDialog1.ShowOpen Label1.Caption=CommonDialog1.filename IfLabel1“"Then Command3.Enabled=-1 Else ExitSub EndIf '把打開的文件名給于label1 '如果label1不為空時(shí),則command3即可用 EndSub -------------- Subdeng() Dimss ss=Shell(Label1.Caption,1) End '啟動指定的文件,并且結(jié)束小鬧鐘程序 EndSub 最后在about對話框中要提的是:在form_load中app.title表示你的應(yīng)用程序的名字;app.major、minor、revision是關(guān)于應(yīng)用程序的版本信息;lblDescription.Caption用于對本程序的一些說明描述之類的話;lblDisclaimer.Caption用于版權(quán)信息或警告等。 好了,至此我們已完成了一個(gè)簡單的VB程序的編寫,希望你能設(shè)計(jì)出更好的鬧鐘程序來!
成都創(chuàng)新互聯(lián)成立于2013年,我們提供高端網(wǎng)站建設(shè)、成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)公司、網(wǎng)站定制、營銷型網(wǎng)站、微信平臺小程序開發(fā)、微信公眾號開發(fā)、seo優(yōu)化服務(wù),提供專業(yè)營銷思路、內(nèi)容策劃、視覺設(shè)計(jì)、程序開發(fā)來完成項(xiàng)目落地,為展覽展示企業(yè)提供源源不斷的流量和訂單咨詢。
vb中獲取系統(tǒng)當(dāng)前的時(shí)間用函數(shù) now() 就可以。另外還有相關(guān)的時(shí)間 date() time()
now()獲取系統(tǒng)當(dāng)前日期和時(shí)間,如:2015-12-12 22:23:34
time()獲取系統(tǒng)的時(shí)間,如:22:23:34不顯示當(dāng)前日期
date()獲得系統(tǒng)的日期,如:2015-12-12
Private Sub Command1_Click()
MsgBox Now()
MsgBox Time()
MsgBox Date
End Sub
還要設(shè)置Format 為 : Custom
用的時(shí)候用DateTimePicker1.Text 不要用value
下面是我隨便用了兩個(gè)DateTimePicker和一個(gè)button一個(gè)textbox演示了一下的代碼,你根據(jù)自己的需要調(diào)試DateTimePicker風(fēng)格
------------------------------------------------
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
----------------------------------------------------------
我的操作系統(tǒng)和.net都是日文的,注釋的東西我刪除了,主要看代碼就好了
這段代碼你可以建一個(gè)空的解決方案,完全復(fù)制到里面去
分享題目:vb.net時(shí)間aaa的簡單介紹
分享鏈接:http://www.chinadenli.net/article20/dosiejo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、響應(yīng)式網(wǎng)站、網(wǎng)頁設(shè)計(jì)公司、軟件開發(fā)、App設(shè)計(jì)、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)