vb.net时钟控件的简单介绍

在VB.net中怎么获取 鼠标在屏幕中的坐标Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long '全屏坐标声明
Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpPoint As POINTAPI) As Int32 '窗口坐标声明
Private Structure POINTAPI '声明坐标变量
Public x As Int32 '声明坐标变量为32位
Public y As Int32 '声明坐标变量为32位
End Structure
'以上是声明部分
'以下是窗口部分
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '用时钟控件来取坐标,窗口上放个Timer组件,Enabled为允许,周期为10到100毫秒均可
Dim P As POINTAPI '声明坐标变量
Dim xx, yy '声明转换要用到的变量
GetCursorPos(P) '获取鼠标在屏幕中的位置
ScreenToClient(Me.Handle.ToInt32, P) '转换为本窗体的坐标
xx = P.x.ToString '把X转换成能显示到文本框的字符串格式
yy = P.y.ToString '把Y转换成能显示到文本框的字符串格式
TextBox1.Text = xx"和"yy '文本框的内容为X坐标和Y坐标
End Sub
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
'
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窗体程序的time控件,可以识别到的最小时间差是多少纳秒 ?VB有现成的函数:
DateDiff(格式,日期1,日期2)
如今天到2010-5-1 8:00:00的时间差,代码:
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时钟控件的简单介绍】vb.net时钟控件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.net时钟控件的信息别忘了在本站进行查找喔 。

    推荐阅读