包含vb.net选择时间控件的词条

vb.net中datetimepicker控件的时间格式问题还要设置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
'
【包含vb.net选择时间控件的词条】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都是日文的,注释的东西我删除了,主要看代码就好了
这段代码你可以建一个空的解决方案,完全复制到里面去
(高分悬赏)用vb.net 做个类似DateTimePicker控件的东西,有调整日期的下拉菜单,但是时间要会动的继承一下DateTimePicker,内置个timer 不断刷新显示
得到焦点停止timer,失去焦点继续timer
把代码贴到项目就会多出一个控件vb.net选择时间控件了
拖出来就能使用
显示格式可以自己设置
---------------------------------------------------------------------------------
''' summary
''' 自动更新vb.net选择时间控件的 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 = https://www.04ip.com/post/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
''' 更新定时器状态
''' /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
''' 根据焦点状态开始、停止更新定时器
''' /summary
DefaultValue(False) _
Public Property AutoUpdateByFocu As Boolean
Get
Set(ByVal value As Boolean)
End Property
''' summary
''' 组件容器
''' /summary
Private components As IContainer = Nothing
''' summary
''' 更新定时器
''' /summary
Private m_tmrUpdate As Timer
End Class
---------------------------------------------------------------------------------
(用C#写的,然后反编译成VB.NET,有图有真相-.-真蛋疼,学C#吧...)
VB.net窗体程序的time控件 , 可以识别到的最小时间差是多少纳秒 ?VB有现成的函数vb.net选择时间控件:
DateDiff(格式,日期1,日期2)
如今天到2010-5-1 8:00:00的时间差vb.net选择时间控件,代码:
DateDiff("yyyy",Now,#2010-5-1 8:00:00#) '还有几(整)年
DateDiff("q",Now,#2010-5-1 8:00:00#) '还有几(整)季度
DateDiff("m",Now,#2010-5-1 8:00:00#) '还有几(整)月
DateDiff("d",Now,#2010-5-1 8:00:00#) '还有几(整)天
DateDiff("ww",Now,#2010-5-1 8:00:00#) '还有几(整)周
DateDiff("h",Now,#2010-5-1 8:00:00#) '还有几(整)小时
DateDiff("n",Now,#2010-5-1 8:00:00#) '还有几(整)分钟
DateDiff("s",Now,#2010-5-1 8:00:00#) '还有几(整)秒
VB.NET,如何用TIMER控件计时这种功能用不到TIMER,TIMER控件用在这种地方也不适合 。(假如你所统计vb.net选择时间控件的时间很短,在几分中内话,可以使用,假如你统计vb.net选择时间控件的时间很长:几小时、几天几夜,建议改用以下方式):
在你需要开始计时的地方加入一个记录当前时间,在你想结束的地方也得到一个当前时间 。然后将两个时间相减 。
希望以上思路可以帮到你 。
VB中的 日期选择 控件 可不可以 一选择日期就可以自动更新 数据DateTimePicker 的值改变时会触发 Change 事件,在那里刷新文本框就行了~~
vb.net选择时间控件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.net选择时间控件的信息别忘了在本站进行查找喔 。

    推荐阅读