You can add a control into a menu, context menu or toolbar by using a ToolStripControlHost class.
Just pass the control reference to constructor of ToolStripControlHost class and then add your ToolStripControlHost instance as a MenuItem in you Menu or .... Just take a look at the code below:
private void Form1_Load(object sender, EventArgs e)
{
MonthCalendar picker = new MonthCalendar();
picker.DateSelected += new DateRangeEventHandler(picker_DateSelected);
ToolStripControlHost host = new ToolStripControlHost(picker);
fileToolStripMenuItem.DropDownItems.Insert(2,host);
}
void picker_DateSelected(object sender, DateRangeEventArgs e)
{
MonthCalendar picker = ((MonthCalendar)sender);
this.Text = picker.SelectionStart.ToString("yyyy/MMM/dd");
}
You can download the sample code:
http://www.tabatabaei.info/csharpsamples/CalendarContext.rar
نسخه فارسي اين پست رو مي تونين از طريق لينك زير پيدا كنين:
DeveloperCenter.ir
No comments:
Post a Comment