Monday, July 16, 2007

Adding a control into Menu or Toolbar

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);

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:

نسخه فارسي اين پست رو مي تونين از طريق لينك زير پيدا كنين: