Get the month click for DateTimePicker in VB.NET

How to check the month arrow click event of DateTimePicker. When I try to change the month of the datetimepicker, it will give the first date of the next month, so I want to prevent that month from clicking .

Please see the picture:

Thank you very much.

Mixing CloseUp and DropDown events and binding data may be the solution

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

How to check the month arrow click event of DateTimePicker. When I try to change the month of the datetimepicker, it will give the first date of the next month, so I To prevent clicks that month.

Please see the picture:

Thank you very much.

p>

Mixed use of CloseUp and DropDown events and binding data may be the solution

Imports System.Windows.Forms< br />
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< /pre>

Leave a Comment

Your email address will not be published.