Develop Office Business Applications using Visual Studio
One of the lesser-known features of Visual Studio Tools for Office is the Microsoft Office Word and Microsoft Office Excel command bar. When you are developing a document-level project for Word or Excel (for example, a Word Document or Excel Workbook project) and you have the document or one of your worksheets open in the designer, this command bar appears in Visual Studio, just above the designer. In Excel, this command bar looks like the following by default.
The first several buttons in this command bar are for changing the keyboard scheme and mapping XML to the document or worksheet. This post is about the purpose of the rest of the buttons.
If you are designing a custom UI for your document or worksheet that includes Windows Forms controls that you add by using the designer, you can use these buttons to arrange the controls with a single click. When you select multiple controls in the designer, these buttons become enabled.
From left to right, here are the buttons you can use:
Align Lefts. This button moves all of the controls to the left, so that they are aligned with the left side of the left-most control.
Align Centers. This button moves all of the controls left or right so that they are aligned around the vertical axis of the widest control.
Align Rights. This button moves all of the controls to the right, so that they are aligned with the right side of the right-most control.
Align Tops. This button moves all of the controls up, so that they are aligned with the top side of the upper-most control.
Align Middles. This button moves all of the controls up or down, so that they are aligned around the horizontal axis of the tallest control.
Align Bottoms. This button moves all of the controls down, so that they are aligned with the bottom side of the bottom-most control.
Make Horizontal Spacing Equal. The left-most and right-most control remain in place; the controls in between move horizontally so that there is equal horizontal space between each control.
A special note about Word. In Word projects, the alignment buttons are enabled only if the selected controls are not in line with text. By default, controls that you add to a Word document at design time are in line with text. To change the layout style of the control, right-click the control and then click Format Control. Then, on the Layout tab, select a wrapping style other than In line with text:
Examples. Enough words! Here are some examples that show these alignment options in action. These examples are pretty contrived, but they should give you an idea of the effects of each option.
Given the following buttons on a worksheet:
Align Lefts rearranges the controls as follows:
Align Centers rearranges the controls as follows:
And Align Rights rearranges the controls as follows:
Align Tops rearranges the controls as follows:
Align Middles rearranges the controls as follows:
And Align Bottoms rearranges the controls as follows:
Make Horizontal Spacing Equal rearranges the controls as follows:
Finally, given the following buttons on a worksheet:
Make Vertical Spacing Equal rearranges the controls as follows:
I hope these options come in handy then next time you are adding controls to a document or worksheet in VSTO.
McLean Schofield, Programming Writer
PingBack from http://home-studio.crutoo.com/2008/04/10/visual-studio-command-bar-for-arranging-controls-on-documents-and/
'Command Button' in Visual Studio 6.0 is replaced with wich button in Visual Studio 2008