還要設(shè)置Format 為 : Custom
成都創(chuàng)新互聯(lián)主要從事成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)忠縣,10年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):028-86922220
用的時(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ù)制到里面去
繼承一下DateTimePicker,內(nèi)置個(gè)timer?不斷刷新顯示
得到焦點(diǎn)停止timer,失去焦點(diǎn)繼續(xù)timer
把代碼貼到項(xiàng)目就會(huì)多出一個(gè)控件了
拖出來(lái)就能使用
顯示格式可以自己設(shè)置
---------------------------------------------------------------------------------
'''?summary
'''?自動(dòng)更新的?DateTimePacker
'''?/summary
Public?Class?MyDateTimePacker
Inherits?DateTimePicker
Public?Sub?New()
Me.components?=?New?Container
Me.m_tmrUpdate?=?New?Timer(Me.components)
Me.m_tmrUpdate.Interval?=?1000
AddHandler?Me.m_tmrUpdate.Tick,?New?EventHandler(AddressOf?Me.m_tmrUpdate_Tick)
MyBase.Format?=?DateTimePickerFormat.Custom
MyBase.CustomFormat?=?"yyyy?年?MM?月?dd?日?hh:mm:ss"
End?Sub
'''?summary
'''?釋放資源
'''?/summary
Protected?Overrides?Sub?Dispose(ByVal?disposing?As?Boolean)
If?(disposing?AndAlso?(Not?Me.components?Is?Nothing))?Then
Me.components.Dispose
End?If
MyBase.Dispose(disposing)
End?Sub
Private?Sub?m_tmrUpdate_Tick(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
MyBase.Value?=?DateTime.Now
End?Sub
Protected?Overrides?Sub?OnEnter(ByVal?e?As?EventArgs)
If?Me.AutoUpdateByFocu?Then
Me.m_tmrUpdate.Stop
End?If
MyBase.OnEnter(e)
End?Sub
Protected?Overrides?Sub?OnLeave(ByVal?e?As?EventArgs)
If?Me.AutoUpdateByFocu?Then
Me.m_tmrUpdate.Start
End?If
MyBase.OnLeave(e)
End?Sub
'?Properties
'''?summary
'''?更新定時(shí)器狀態(tài)
'''?/summary
Public?Property?AutoUpdate?As?Boolean
Get
Return?Me.m_tmrUpdate.Enabled
End?Get
Set(ByVal?value?As?Boolean)
Me.m_tmrUpdate.Enabled?=?value
End?Set
End?Property
'''?summary
'''?根據(jù)焦點(diǎn)狀態(tài)開始、停止更新定時(shí)器
'''?/summary
DefaultValue(False)?_
Public?Property?AutoUpdateByFocu?As?Boolean
Get
Set(ByVal?value?As?Boolean)
End?Property
'''?summary
'''?組件容器
'''?/summary
Private?components?As?IContainer?=?Nothing
'''?summary
'''?更新定時(shí)器
'''?/summary
Private?m_tmrUpdate?As?Timer
End?Class
---------------------------------------------------------------------------------
(用C#寫的,然后反編譯成VB.NET,有圖有真相-.-真蛋疼,學(xué)C#吧...)
這種功能用不到TIMER,TIMER控件用在這種地方也不適合。(假如你所統(tǒng)計(jì)的時(shí)間很短,在幾分中內(nèi)話,可以使用,假如你統(tǒng)計(jì)的時(shí)間很長(zhǎng):幾小時(shí)、幾天幾夜,建議改用以下方式):
在你需要開始計(jì)時(shí)的地方加入一個(gè)記錄當(dāng)前時(shí)間,在你想結(jié)束的地方也得到一個(gè)當(dāng)前時(shí)間。然后將兩個(gè)時(shí)間相減。
希望以上思路可以幫到你。
新聞標(biāo)題:包含vb.net選擇時(shí)間控件的詞條
網(wǎng)站路徑:http://muchs.cn/article46/ddccohg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、App設(shè)計(jì)、網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)