Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Windows and Controls Code Examples

Preventing a DTPicker (date picker) control from changing

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
Preventing a DTPicker (date picker) control from changing The default behaviour of the DTPicker control is to change the date when scrolling through the dates with the calendar. The following code ensures that the date only changes when you select a new date. This is particulary useful when using two controls to specific date ranges. Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private zdtCurrentDate As Date, zdtNewValue As Date 'Purpose : Test to see if a DTPicker's calendar is visible 'Inputs : N/A 'Outputs : Returns True if a DTPicker's calendar is visible 'Notes : You will need to a the MSCOMCT2.OCX component to your project Function DatePickerAreaVisible() As Boolean If FindWindow("msvb_lib_monthview", "") Then DatePickerAreaVisible = True Else DatePickerAreaVisible = False End If End Function 'This demonstration prevents the date changing while the date calendar is visible Private Sub DTPicker1_Change() Static sbNoRecursion As Boolean If DatePickerAreaVisible Then sbNoRecursion = True zdtNewValue = DTPicker1.Value DTPicker1.Value = zdtCurrentDate sbNoRecursion = False End If End Sub Private Sub DTPicker1_CloseUp() DTPicker1.Value = zdtNewValue End Sub Private Sub DTPicker1_DropDown() 'Store the current date when the calendar is shown zdtCurrentDate = DTPicker1.Value End Sub