Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,

I am using DateTimePicker control in Windows Application.

If I select DateTimePicker is displayed.

My requirement is to display two calenders, those are current month and next month.

I placed MonthCalender under the DateTimePicker When I select DateTimePicker It's own calender also displayed. and also MonthCalender's selected value is not getting in
DateTimePicker.


Is there any way please help me.


Thanks & Regards
Posted
Updated 8-Aug-11 0:43am
v2
Comments
Praveen Kullu 8-Aug-11 6:53am    
I believe you had posted the same question sometime ago and I had helped you solve it. Didn't you check my last comment? I gave you the idea.

C#
private void form1_load(...)
{
dateTimePicker1.Value = DateTime.Now.AddDays(30);
}

MonthCalendar mc = new MonthCalendar();
private void dateTimePicker1_DropDown(object sender, EventArgs e)
{
    mc.DateChanged +=new DateRangeEventHandler(mc_DateChanged); //add new event handler 
    mc.MouseEnter +=new EventHandler(mc_MouseEnter);
    mc.Location = new Point(dateTimePicker1.Location.X + dateTimePicker1.Size.Width , dateTimePicker1.Location.Y +20);
    this.Controls.Add(mc);
    mc.Show();
}
private void mc_MouseEnter(object sender, EventArgs e)
{
    mc.BringToFront();
    mc.Focus();
}
 
private void mc_DateChanged(object sender, DateRangeEventArgs e)
{
    mc.Hide();
    dateTimePicker1.Value = e.Start;
}
private void dateTimePicker1_CloseUp(object sender, EventArgs e)
{
//cln.Hide(); //just for timebeing
}


I hope I have finally solved your question. Vote for it if it worked and then mark it as solved.
 
Share this answer
 
v3
Comments
kranthi.oru 8-Aug-11 7:28am    
hi praveen from ur code i got current month but I want next month.
i.e by ur code iam getting august month but i want september month and also if iam slected second month that value also displayed in datetime picker For this what can i do ?
if u know please help me.
Praveen Kullu 8-Aug-11 7:57am    
Unfortunately, the datetimepicker control doesn't gives focus to the calender control and select its value until the datetimepicker is closeup. Here is an alternate solution. It's not perfect but i hope it works for timebeing.
kranthi.oru 10-Aug-11 8:02am    
Hi praveen I Got Finally The Answer Pls watch this.
hi
to all I got finally solution. I send this solution to all for future use.

First of all add a picturebox inside DateTimepicker. Add a image inside a picture box That image look \/ i.e at the end of datetime picker what is contains.

In form load hide monthcalender. Picture-box click event show monthcalender.
See The code here


    private void Form1_Load(object sender, EventArgs e)
        {
            monthCalendar1.Hide();
        }

      

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
           
            monthCalendar1.SetDate(dateTimePicker1.Value);
         
        }
         
        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            dateTimePicker1.Value = Convert.ToDateTime(monthCalendar1.SelectionStart.ToShortDateString());
            monthCalendar1.Hide();
     
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            monthCalendar1.Hide();
        }

        private void dateTimePicker1_MouseDown(object sender, MouseEventArgs e)
        {
            monthCalendar1.Hide();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            monthCalendar1.Show();
           monthCalendar1.Focus();
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {

            dateTimePicker1.Value = Convert.ToDateTime(monthCalendar1.SelectionStart.ToShortDateString());
        }

      
       
    }
}


This is exact for my requirement Please watch This
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900