PrepAway - Latest Free Exam Questions & Answers

Which code segment should you add at line 02?

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

01 CustomControl myControl = new CustomControl();
02

You need to ensure that an instance of CustomControl is displayed on the form as a top-level item of the ctxMenu control. Which code segment should you add at line 02?

PrepAway - Latest Free Exam Questions & Answers

A.
ToolStripControlHost host = new ToolStripControlHost(myControl);ctxMenu.Items.Add(host);

B.
ToolStripPanel panel = new ToolStripPanel();panel.Controls.Add(myControl);ctxMenu.Controls.Add(panel);

C.
ToolStripContentPanel panel = new ToolStripContentPanel();panel.Controls.Add(myControl);ctxMenu.Controls.Add(panel);

D.
ToolStripMenuItem menuItem = new ToolStripMenuItem();
ToolStripControlHost host = new ToolStripControlHost(myControl);
menuItem.DropDownItems.Add(host);ctxMenu.Items.Add(menuItem);


Leave a Reply