What should you do?

You are creating a Windows Form that includes a TextBox control named txtDate. When a user right-clicks within the text box, you want the application to display a MonthCalendar control. You need to implement a context menu that provides this functionality. What should you do?

You are creating a Windows Form that includes a TextBox control named txtDate. When a user right-clicks within the text box, you want the application to display a MonthCalendar control. You need to implement a context menu that provides this functionality. What should you do?

A.
Add the following code to the form initialization.
MonthCalendar cal = new MonthCalendar();
ContextMenuStrip mnuContext = new ContextMenuStrip();
ToolStripControlHost host = new ToolStripControlHost(mnuContext);
txtDate.ContextMenuStrip = mnuContext;

B.
Add the following code to the form initialization.
ContextMenuStrip mnuContext = new ContextMenuStrip();
MonthCalendar cal = new MonthCalendar();
ToolStripControlHost host = new ToolStripControlHost(cal);
mnuContext.Items.Add(host);
txtDate.ContextMenuStrip = mnuContext;

C.
Add the following code to the form initialization.
ToolStripContainer ctr = new ToolStripContainer();
MonthCalendar cal = new MonthCalendar();
ctr.ContentPanel.Controls.Add(cal);
txtDate.Controls.Add(ctr);
Add a MouseClick event handler for the TextBox control that contains the following code.
if (e.Button == MouseButtons.Right) {
txtDate.Controls[0].Show();
}

D.
Add a MouseClick event handler for the TextBox control that contains the following code.
if (e.Button == MouseButtons.Right) {
ContextMenuStrip mnuContext = new ContextMenuStrip();
MonthCalendar cal = new MonthCalendar();
ToolStripControlHost host = new ToolStripControlHost(cal);
mnuContext.Items.Add(host);
txtDate.ContextMenuStrip = mnuContext;
}



Leave a Reply 0

Your email address will not be published. Required fields are marked *