Public Class OwnDatePicker Private WithEvents monCalendar As Dialog_Calendar 'Quand l'utilisateur click sur le bouton permettant d'effacer la date Private Sub Btn_EffaceDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_EffaceDate.Click TBX_Date.ResetText() End Sub 'Quand l'utilisateur click sur le bouton permetant d'afficher le calendrier Private Sub Btn_AfficheCalendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_AfficheCalendar.Click Dim maDate As Date Dim monPoint As Drawing.Point monCalendar = New Dialog_Calendar If TBX_Date.Text <> "" Then maDate = TBX_Date.Text monCalendar.MCd_Calendrier.SetDate(maDate) End If 'TopFromScreen est une fonction que j'ai créée qui permet de récupérer la position absolu d'un controle dans l'écran (le moniteur) monPoint = TopFromScreen(Btn_AfficheCalendar) monCalendar.Location = New Point(monPoint.X + Btn_AfficheCalendar.Width, monPoint.Y + Btn_AfficheCalendar.Height) monCalendar.Show() End Sub 'Quand l'utilisateur à changé la date du calendrier Private Sub Calendar_OnDateSelectedChanged(ByVal sender As System.Object, ByVal e As Windows.Forms.DateRangeEventArgs) Handles monCalendar.OnSelectedDateChanged TBX_Date.Text = monCalendar.GetSelectedDate monCalendar.Close() End Sub End Class
Imports System.Windows.Forms Public Class Dialog_Calendar Public Delegate Sub SelectedDateChangedEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Public Event OnSelectedDateChanged As SelectedDateChangedEventHandler 'lorsque l'utilisateur choisi une date Private Sub MCd_Calendrier_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MCd_Calendrier.DateSelected 'On leve un evenement RaiseEvent OnSelectedDateChanged(sender, e) End Sub 'Lorsque la fenetre perd le focus Private Sub Me_Deactivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Deactivate Me.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.Close() End Sub ''' <summary> ''' Renvoit la Date Selectionnée par l'utilisateur ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Public Function GetSelectedDate() As Date Return MCd_Calendrier.SelectionRange.Start() End Function End Class