You are creating a Windows Forms application by using the .NET Framework 3.5. You create a new form in the application. You add a ContextMenuStrip control named ctxMenu to the form. You have a user-defined class named CustomControl. You write the following code segment in the application. (Line numbers are included for reference only.) CustomControl myControl = new CustomControl(); You need to ensure that an instance of CustomControl is displayed on the form as a top-level item of the ctxMenu control. What line of code should you write to do so?

Options
- ToolStripControlHost host = new ToolStripControlHost(myControl); ctxMenu.Items.Add(host);
- ToolStripPanel panel = new ToolStripPanel(); panel.Controls.Add(myControl); ctxMenu.Controls.Add(panel);
- ToolStripContentPanel panel = new ToolStripContentPanel(); panel.Controls.Add(myControl); ctxMenu.Controls.Add(panel);
- ToolStripMenuItem menuItem = new ToolStripMenuItem(); ToolStripControlHost host = new ToolStripControlHost(myControl); menuItem.DropDownItems.Add(host); ctxMenu.Items.Add(menuItem);


CORRECT ANSWER : ToolStripControlHost host = new ToolStripControlHost(myControl); ctxMenu.Items.Add(host);

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement