You are busy adding a MenuStrip control, which has an instance of a ToolStripMenu item named testjobItem, to a form in a Microsoft Windows Forms application. This item’s display text is Job. You have received instructions to add two menu items to the Job menu item. The first item’s display text should be Create New Job, and the second one is Run Job. Which code segment should you use to programmatically add the two menu items?
A.
ToolStripMenuItem createNewJobItem = new ToolStripMenuItem["Create New Job"];
ToolStripMenuItem runJobItem = new ToolStripMenuItem["Run Job"];
jobItem.Container.Add[createNewJobItem];
jobItem.Container.Add[runJobItem];
B.
ToolStripMenuItem createNewJobItem = new ToolStripMenuItem["Create New Job"];
ToolStripMenuItem runJobItem = new ToolStripMenuItem["Run Job"];
jobItem.Owner.Items.Add[createNewJobItem];
jobItem.Owner.Items.Add[runJobItem];
C.
ToolStripMenuItem createNewJobItem = new ToolStripMenuItem["Create New Job"];
ToolStripMenuItem runJobItem = new ToolStripMenuItem["Run Job"];
ToolStripMenuItem[] items = new ToolStripMenuItem[]{create NewJobItem, runJobItem}
jobItem.DropDownItems.AddRange[items];
D.
ToolStripMenuItem createNewJobItem = new ToolStripMenuItem["Create New Job"];
ToolStripMenuItem runJobItem = new ToolStripMenuItem["Run Job"];
ToolStripMenuItem[] items = new ToolStripMenuItem[]{create NewJobItem, runJobItem}
jobItem.Owner.Items.AddRange[items];
Explanation:
For the jobItem instance you should call the AddRange. The property of the DropDownItems represents a collection of child items of the jobItem instance, which allows you to add the two items to the job menu item.Incorrect Answers:
A: This property returns an instance of IContainer, which represents a logical container for other components.
B: The Owner property returns the Menu script instance that owns the ToolStripMenuItem instance.