I created a custom datetimepicker based on the UserControl
in Visual Studio 2010 c#. There are a RichTextBox
, a Button
and MonthCalendar
in this control.
https://i.stack.imgur.com/zT8Lw.png.
I change height of the UserControl to hide/show calendar. My problem is that when I place this control on the GroupBox
which is located on the panel, parent overlaps it:
https://i.stack.imgur.com/JQMuo.png
I've solved this looping back on controls Parent until the main form is found and then setting it as parent of my DateTimePicker.
Control parent = this.Parent ?? null;
while (parent != null)
{
if (parent is Form)
break;
parent = parent.Parent;
}
this.clnMonth.Parent = parent;
clnMonth.Location = this.PointToScreen(Point.Empty);
I've tried to place MonthCalendar
on another form and show/hide it after click, but there where huge problem positioning the form under the DateTimePicker. The above method works fine, but I know it's not the best solution. Could you give me any alternative idea?