Override DoublClick Event of MonthCalendar

212 views
Skip to first unread message

John

unread,
Oct 19, 2001, 3:55:05 PM10/19/01
to
Hello everyone,
I am trying to override the doubleClick/onDoubleClick event on the
system.windows.forms.monthcalendar control. I have played around with the
AddHandler and I am able to override the DateSelected event, but I cannot do
the same for the DoubleClick (or Click) event. They seem to be some type of
hidden events. I know they exist because I can see them in the Object
Browser.

I am creating the monthcalendar control at run time and I am not sure if
this makes a difference, but I wouldn't think that it should. Any help or
pointers in the right direction would be great. Thanks...

-John


Jacob Grass (MVP)

unread,
Oct 19, 2001, 4:31:20 PM10/19/01
to
Unfortunately, the MonthCalendar control does not fire a Click or DoubleClick event. I am not sure why this is. What is it you are trying to accomplish? Perhaps there is a "workaround." If this event is only supposed to fire when a date is double-clicked, you could probably handle it in the DateSelected event and just keep track of the clicks.

Perhaps someone from MS can comment on why (and how) these events don't fire even if they appear to be present. . .

--
Jacob Grass
Microsoft .NET MVP

"John" <knowt...@hotmail.com> wrote in message news:OjNS9fNWBHA.2416@tkmsftngp05...

John

unread,
Oct 19, 2001, 4:40:11 PM10/19/01
to
I have a button that creates the calendar control during runtime and then
when a date is doubleClicked I want it to update a textbox I have on the
form. I thought about trapping for the number of clicks, is there a way to
do this easily or would I need to add a timer and all the crap to keep
track? I thought this would be something really simple that now I am
thinking I should just use the OCX control we have from VB6 :)
I am not using the DatetimePicker for several reasons one of which there is
no way of clearing the date completely from the control. The control only
has a checkbox to nullify the date and end users will have no idea what this
check box does plus it is ugly as all get out :)

Any ideas would be great, thanks again
-John

"Jacob Grass (MVP)" <JGr...@AbilitiSolutions.com> wrote in message
news:u#TEOxNWBHA.992@tkmsftngp03...

Jacob Grass (MVP)

unread,
Oct 19, 2001, 5:32:52 PM10/19/01
to
John-

Try this: (assumes a monthcalendar control called MonthCalendar1 and a textbox control called TextBox1)


Private m_NumClicks As Short = 0
Private m_FirstClick As Long

Private Sub MonthCalendar1_DateSelected( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) _
Handles MonthCalendar1.DateSelected

If m_NumClicks >= 2 Then
TextBox1.Text = e.Start.Date.ToString
m_NumClicks = 0
End If

End Sub

Private Sub MonthCalendar1_MouseDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MonthCalendar1.MouseDown

If e.Button = MouseButtons.Left Then
If m_NumClicks = 0 Then
m_FirstClick = Now.Ticks
m_NumClicks += 1
ElseIf (Now.Ticks - m_FirstClick) > 2000000 Then
m_NumClicks = 0
Else
m_NumClicks += 1
End If
End If
End Sub

Let me know if you have any questions.


--
Jacob Grass
Microsoft .NET MVP

"John" <knowt...@hotmail.com> wrote in message news:OYVsJ5NWBHA.1144@tkmsftngp05...

John

unread,
Oct 22, 2001, 11:44:39 AM10/22/01
to
Thanks this is exactly what I needed. How did you come up with the
"2000000" number?


Thanks again,
-John


Jacob Grass (MVP)

unread,
Oct 22, 2001, 12:44:19 PM10/22/01
to
A Tick is an interval equivalent to 100 nanoseconds. So, 2 million Ticks is 200 million nanoseconds. Nano- = 10^-9. So, you end up with two tenths of a second. This is what I pulled out of mid-air when trying to estimate the average double-click speed. : )

--
Jacob Grass
Microsoft .NET MVP

"John" <knowt...@hotmail.com> wrote in message news:eCg5cSxWBHA.2208@tkmsftngp05...

Reply all
Reply to author
Forward
0 new messages