If you use the mousedown event, the x and y coordinates available in the
mouseeventargs are relative to the control. Because the mousedown event
happens after the datechanged event, you have to do a workaround to
effectively reverse the order.
I know this may seem a crude way to go about it, but if you create a timer
(form level, withevents). Set the timer's duration for 100ms in the
Form_Load event.
Create an event handler for Timer_Tick.
Create a form level variable that will hold your DateRangeEventArgs until
the timer fires...Private DateRangeEventArgs as DateRangeEventArgs. That way
the timer's tick event handler can act as a delayed proxy for your
DateChanged event handler. Just port the code over.
After you stash the DateRangeEventArgs, Start the timer in the date changed
event handler. During the 100ms while the Timer is waiting to fire, the
mousedown event will fire and there you can stash the MouseEventArgs in a
form level variable. The MouseEventArgs contains your mouse X and Y
coordinates relative to the control.
In the timer_tick event handler, stop the timer, and then do your tests:
the two addmonth tests, as mentioned in previous message, and if either of
those are true, test if Me.MouseEventArgs.Y is less than 24 (or whatever your
click testing indicates...actually you could fudge it to allow a few extra
hundredths and be safe). If the user uses the keyboard arrow keys, instead
of the mouse, to change dates, there will be no mousedown event, and
therefore no MouseEventArgs...handle that as needed.
Lastly, in the timer routine, reset your applicable formwide variables to
their wait-state values...
Me.MouseEventArgs = Nothing, Me.DateRangeEventArgs = Nothing
You may want to adjust the timer's interval, but I think 100ms should be
good. You may be able to take it down to 50 or so. I have tried using a new
Thread for this kind of workaround, but I find the Timer to be more
predictable and reliable.
> I'm struggling with identifying whether a user has clicked on the left
> or right arrows within the MonthCalendar controls. I had a good
[quoted text clipped - 30 lines]
> Thanks,
> Randy
Annie McCall - 14 Oct 2007 23:25 GMT
I answered same on your other thread on MonthCalendar.
View Message Thread (11 replies)
? Previous Page Results 11 - 12 of 12
Capture Month Change with MonthCalendar
From: Unknown User
Date Posted: 10/14/2007 8:42:00 AM
Hi Randy,
I am having the same problem. I need to know whether they clicked on the
arrow to change the month or actually selected a date.
I have you had any luck solving this? Can you post your solution?
In the meantime, I will continue researching for some solution. I will
post if I have any success.
This seems so basic. I'm sure we'll find a solution.
Thanks,
Annie
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Re: Capture Month Change with MonthCalendar
From: Annie McCall
Date Posted: 10/14/2007 10:26:00 AM
Hi Randy,
I found a solution that works very well for me.
private void monthCalendarDate_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {
MonthCalendar.HitTestInfo oHTI = monthCalendarDate.HitTest(e.X,e.Y);
if ( oHTI.HitArea == MonthCalendar.HitArea.PrevMonthButton){
MessageBox.Show("Left arrow hit");
return;
}
if ( oHTI.HitArea == MonthCalendar.HitArea.NextMonthButton)
{
MessageBox.Show("Right arrow hit");
return;
}
if ( oHTI.HitArea == MonthCalendar.HitArea.Date ||
oHTI.HitArea == MonthCalendar.HitArea.PrevMonthDate
oHTI.HitArea ==
MonthCalendar.HitArea.NextMonthDate){
this.txtJobDate.Text =
this.dateValue_Renamed; this.monthCalendarDate.Visible = false;
}
}
You can detect in MouseDown event using the hitarea. In my case I only
wanted to set the visible property of my monthcalendar to false if they
actually entered a date.
dateValue_Renamed is a global variable I set in the datechange event.
Hope this helps you.
Annie McCall
Charlie - 16 Oct 2007 06:28 GMT
Annie,
I replied to one of Randy's 10/14 messages (in the thread that he started on
10/6) with some code I wrote and tested.
> I answered same on your other thread on MonthCalendar.
>
[quoted text clipped - 73 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Annie McCall - 14 Oct 2007 23:49 GMT
I answered same on your other thread on MonthCalendar.
View Message Thread (11 replies)
? Previous Page Results 11 - 12 of 12
Capture Month Change with MonthCalendar
From: Unknown User
Date Posted: 10/14/2007 8:42:00 AM
Hi Randy,
I am having the same problem. I need to know whether they clicked on the
arrow to change the month or actually selected a date.
I have you had any luck solving this? Can you post your solution?
In the meantime, I will continue researching for some solution. I will
post if I have any success.
This seems so basic. I'm sure we'll find a solution.
Thanks,
Annie
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Re: Capture Month Change with MonthCalendar
From: Annie McCall
Date Posted: 10/14/2007 10:26:00 AM
Hi Randy,
I found a solution that works very well for me.
private void monthCalendarDate_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {
MonthCalendar.HitTestInfo oHTI = monthCalendarDate.HitTest(e.X,e.Y);
if ( oHTI.HitArea == MonthCalendar.HitArea.PrevMonthButton){
MessageBox.Show("Left arrow hit");
return;
}
if ( oHTI.HitArea == MonthCalendar.HitArea.NextMonthButton)
{
MessageBox.Show("Right arrow hit");
return;
}
if ( oHTI.HitArea == MonthCalendar.HitArea.Date ||
oHTI.HitArea == MonthCalendar.HitArea.PrevMonthDate
oHTI.HitArea ==
MonthCalendar.HitArea.NextMonthDate){
this.txtJobDate.Text =
this.dateValue_Renamed; this.monthCalendarDate.Visible = false;
}
}
You can detect in MouseDown event using the hitarea. In my case I only
wanted to set the visible property of my monthcalendar to false if they
actually entered a date.
dateValue_Renamed is a global variable I set in the datechange event.
Hope this helps you.
Annie McCall