tags:

views:

53

answers:

1

there is a MonthCalender in C#

There is a 2 buttons to select the month

Jan, Feb and so on..

Anyway I can detect that the user changed the month?

+1  A: 

try this

private int MonthValue = 0;
private bool bChanged = false;
private void Form1_Load(object sender, EventArgs e)
{
    MonthValue = monthCalendar1.TodayDate.Month;
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{

    if (MonthValue != monthCalendar1.SelectionStart.Month)
    {
        //changed
        bChanged = true;
        MonthValue = monthCalendar1.SelectionStart.Month;
    }
    else
    {
        //not changed
        bChanged = false;
    }
}
Raymund
Yea.. that's a correct answer. But that only works when u click the Month's name and select a different month.if you click 2 buttons with ">" or "<" icon, it will show the month has changed but it continue changing
william
Have you tried using it as for me it works fine using "<" or ">".
Raymund
Yes, I already tried.
william
I put a messagebox if it goes into if statement. So the messagebox pops up new month. If i click that new month, next month pops up again.. and it pops up non stop
william
Is this what you mean? private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e){ if (MonthValue != monthCalendar1.SelectionStart.Month) { //changed bChanged = true; MonthValue = monthCalendar1.SelectionStart.Month; MessageBox.Show("New month"); } else { //not changed bChanged = false; }}
Raymund
Yes.. in MessageBox, instead of "New month", I wrote MonthValue.ToString()So Current month is 10. If I click ">", 11 pops up. When I click OK, 12 pops up followed by 1,2,3 and so on..
william
Check your events it might be firing in some other location as well, for me it worked fine. I only placed the code on the DateChanged event and nothing else.
Raymund
yea.. me too.. I created a new proj and drag only one month calender.there are only form load event and date changed event.
william
What .Net version are you using? and what OS. I'm using Win7 and .Net 4, that might have a impact, but not sure
Raymund
I m using XP .net 2.
william
I found out that the ">" button or the "<" is continue clicking whenever I write something in date changed event. Even a message box showing "Change". keep on showing "Change". My frd is using XP and .net 4, also have the same problem.
william
IT IS WORKING.. as long as you don't pop up any message box.
william
mmm, Nice to hear thats its working now
Raymund
Ok. Thanks a lot.
william