Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Privet! Hello!
I'm writing a Windows Forms application in C# for WinXP. On a main form I have a MaskedTextBox control for a date to be entered by a user. Beside the text box there's a button which should call a pop-up calendar by pressing on it. A user then picks up a date, the calendar closes, and the date appears in the text box.

An ordinary form shows up easily when the button is pressed:
C#
private void btnBeginDate_Click(object sender, EventArgs e)
{
    Form frm = new Form();
    frm.Show(); // The 'frm' form appears
}

But the MonthCalendar control won't show up in such manner:
C#
private void btnBeginDate_Click(object sender, EventArgs e)
{
    MonthCalendar MCalendar = new MonthCalendar();
    MCalendar.Show(); // Nothing visible happens
}

So how should I implement this? I can't open a pop-up calendar.

Thanks in advance.
Posted

First of all, you did not add an instance of calendar to anything. The method Show is just irrelevant. It's the antonym of Hide. You only need to call Show for forms. What you need is adding:

C#
MonthCalendar MonthCalendar = new MonthCalendar();
Panel PanelCalendar = new Panel();

//...

MonthCalendar.//... setup all kind of properties you may need: dock, size, options...
//...

PanelCalendar.Controls.Add(MonthCalendar); //that's is
//or:
//MonthCalendar.Parent = PanelCalendar; //same thing


All controls are inserted in each other in hierarchy, up to the parent form. There is no functional parent-child relationship between forms though, instead, use OwnedForm/Owner relationship if you use more than one.

Any kind of pop-up is bad, especially you are going to create and insert an instance of your calendar over and over. If you don't want to see it on the form permanently and update it on some events (but why not?), you can add it once and hide/show, shrink the parent panel, hide it in a tab of TabControl which you can select on demand, dock it… so many sensible options. Pop-ups are intrusive, inconvenient and, I would say… childish. :-)

—SA
 
Share this answer
 
v6
Comments
Sander Rossel 23-Nov-11 13:34pm    
All correct, my 5.
Sergey Alexandrovich Kryukov 23-Nov-11 13:44pm    
I was pretty sure it is. :-)
Thank you, Naerling.
--SA
LanFanNinja 23-Nov-11 13:43pm    
+5 Yes popup make me very mad!
Sergey Alexandrovich Kryukov 23-Nov-11 13:44pm    
Thank you.
Don't get mad, exterminate them! :-)
--SA
Uday P.Singh 23-Nov-11 14:27pm    
5ed :)
MonthCalendar is a control you add to your form not a form itself. If you want to display it then set the Visible property to true;
 
Share this answer
 

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