Creating a UI for a Windows Forms application by using standard controls
By —
Questions derived from the 70-526CSHP - TS: Microsoft .NET Framework 2.0 - Windows-Based Client Development (C# .NET) Microsoft Self-Test Software Practice Test.
Objective: Creating a UI for a Windows Forms application by using standard controls
SubObjective: Add and configure a Windows Forms control
Item Number: 70-526CSHP.1.3.1
Single Answer, Multiple Choice
You are an application developer at a company. You need to create a Windows application that contains a ToolStrip control situated horizontally in the upper edge of the Windows form. To allow your ToolStrip control to be draggable to each side of the form, you decide to use a ToolStripContainer. You have added a ToolStripContainer control named toolStripContainer1 and a ToolStrip control named toolStrip1 on the Windows form at run-time.
Which code should you add to the Windows form at run-time so that the toolStrip1 control will appear at the top of the Windows form?
- toolStripContainer1.RightToolStripPanel.Controls.Add( toolStrip1 );
Controls.Add( toolStripContainer1 ); - toolStripContainer1.LeftToolStripPanel.Controls.Add( toolStrip1 );
Controls.Add( toolStripContainer1 ); - toolStripContainer1.BottomToolStripPanel.Controls.Add( toolStrip1 );
Controls.Add( toolStripContainer1 ); - toolStripContainer1.TopToolStripPanel.Controls.Add( toolStrip1 );
Controls.Add( toolStripContainer1 );
Answer:
D. toolStripContainer1.TopToolStripPanel.Controls.Add( toolStrip1 );
Controls.Add( toolStripContainer1 );
Tutorial:
You should add the following code:
toolStripContainer1.TopToolStripPanel.Controls.Add( toolStrip1 );
Controls.Add( toolStripContainer1 );
This code uses the TopToolStripPanel property of the ToolStripContainer control. The ToolStripContainer is a container control that allows you to control strip controls, such as MenuStrip, ToolStrip, StatusStrip and ContextMenuStrip controls, at the form level. After adding a ToolStripContainer to a form, you can add other controls to its content panel, and add other strip controls to the four other panels that are available on each side of the form. The TopToolStripPanel property is used to specify the top panel of the ToolStripContainer control. In this scenario, this property gets the top panel of the toolStripContainer1 control and adds the toolStrip1 control in the top panel by using the Add method. Therefore, the ToolStrip control will appear on the top of the Windows form when executing the application.
You should not add the code that uses the RightToolStripPanel property of the ToolStripContainer control. The TopToolStripPanel property is used to specify the right panel of the ToolStripContainer control. In this code, this property gets the right panel of the toolStripContainer1 control and adds the toolStrip1 control in the right panel by using the Add method. Therefore, the ToolStrip control will appear on the right edge of the Windows form when executing the application.
You should not add the code that uses the LeftToolStripPanel property of the ToolStripContainer control. The TopToolStripPanel property is used to specify the left panel of the ToolStripContainer control. In this code, this property gets the left panel of the toolStripContainer1 control and adds the toolStrip1 control in the left panel by using the Add method. Therefore, the ToolStrip control will appear on the left edge of the Windows form control when executing the application.
You should not add the code that uses the BottomToolStripPanel property of the ToolStripContainer control. The BottomToolStripPanel property is used to specify the bottom panel of the ToolStripContainer control. In this code, this property gets the bottom panel of the toolStripContainer1 control and adds the toolStrip1 control in the bottom panel by using the Add method. Therefore, the ToolStrip control will appear on the bottom of the Windows control when executing the application.




