Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

How to: Support Localization on Windows Forms Using AutoSize and the TableLayoutPanel Control 

One of the difficulties you may encounter when you localize your application is changes to your layout introduced by text strings of varying lengths. The AutoSize property and the TableLayoutPanel control can be helpful in creating layouts that can adapt to different text string lengths that you cannot anticipate at design time.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Enabling a Layout that Adapts to Varying String Sizes

The AutoSize property causes a control to size itself to its content. The TableLayoutPanel control provides a proportional resizing capability that enables controls to retain the same relative size when they are resized to fit their contents.

To enable automatic sizing for localization

  1. Drag a TableLayoutPanel control from the Toolbox onto your form. Set the value of the RowCount property to 1. Set the value of the AutoSize property to true.

  2. Drag a Button control from the Toolbox into the left cell in the TableLayoutPanel control. Set the value of its AutoSize property to true.

  3. Open the Columns and Row Styles dialog box. For more information, see How to: Edit Columns and Rows in a TableLayoutPanel Control. Select Column1 and change the value of its SizeType property to AutoSize. Click the OK button to accept your changes.

  4. Set the value of the Button control's Text property to a long string, for example "This is a long string to demonstrate a localizable form." The Button control and the TableLayoutPanel cell are resized to fit the new string length.

  5. Change the value of the Button control's Text property to a short string. The width of the Button control and the TableLayoutPanel cell are reduced to fit the shorter string.

  6. Move the TableLayoutPanel control so it is flush with the lower-right corner of the form.

  7. Set the value of the form's AutoSize property to true.

  8. Change the value of the Button control's Text property to a long string, for example "This is a long string to demonstrate a localizable form." If the string is long enough, it causes the TableLayoutPanel control and the form to increase in size.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.