gpt4 book ai didi

vb.net - 在VB.net中获取DateTimePicker的月份点击

转载 作者:行者123 更新时间:2023-12-01 05:23:45 25 4
gpt4 key购买 nike

如何检查 DateTimePicker 的月份箭头单击事件。当我尝试更改 datetimepicker 的月份时,它会给出下个月的第一个日期,所以我必须阻止该月的点击。

请看图片:

enter image description here

非常感谢。

最佳答案

混合使用 CloseUp 和 DropDown 事件和绑定(bind)数据可能是解决方案

Imports System.Windows.Forms

Namespace WindowsFormsApplication1
Public Partial Class Form1
Inherits Form
Private isDropedDown As Boolean
Private m_dataSale As DateTime = DateTime.Now
Public Property DataSale() As DateTime
Get
Return m_dataSale
End Get
Set
If isDropedDown Then
If m_dataSale.[Date].AddMonths(1).[Date] = value.[Date] OrElse m_dataSale.[Date].AddMonths(-1).[Date] = value.[Date] OrElse New DateTime(m_dataSale.Year, m_dataSale.Month, 1).AddMonths(1).[Date] = value.[Date] OrElse New DateTime(m_dataSale.Year, m_dataSale.Month, 1).AddMonths(-1).[Date] = value.[Date] Then
MessageBox.Show("Month is changing")
End If
End If

m_dataSale = value
End Set
End Property

Public Sub New()
InitializeComponent()
Dim binding = dateTimePicker1.DataBindings.Add("Value", Me, "DataSale")
binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
End Sub
Private Sub dateTimePicker1_CloseUp(sender As Object, e As EventArgs)
isDropedDown = False
End Sub

Private Sub dateTimePicker1_DropDown(sender As Object, e As EventArgs)
isDropedDown = True
End Sub
End Class
End Namespace

关于vb.net - 在VB.net中获取DateTimePicker的月份点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15024164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com