Windows Forms


This section details the .NET Framework 2.0 and Visual Studio 2005 enhancements which are specific to Windows Forms applications.

Property Reflection Model

Visual Studio 2005 supports a model for serializing Windows Forms called property reflection. Instead of properties being serialized one by one as they are in Visual Studio 2003's property assignment model, properties are loaded using reflection by searching for resources with names that match the control and its properties. The end result is no different from the end result of Visual Studio 2003 in terms of functionality. The difference lies in the performance of forms that have large numbers of controls, so property reflection is said to scale better than property assignment. See Chapter 4.

Control.AutoSize

In the .NET Framework 1.1, several controls have an AutoSize property, but many do not. In the .NET Framework 2.0, the AutoSize property has been moved to the System.Windows.Forms.Control base class, meaning that all controls now have an AutoSize property. You will find that a few controls (e.g., ListBox) hide their AutoSize property in the Form Designer, but putting these controls aside this means that significantly more controls in Windows Forms 2.0 have an AutoSize property. See the "AutoSize" section in Chapter 8, "Best Practices."

Label.AutoSize Default

The default for Label.AutoSize remains unchanged in the .NET Framework 2.0 and is still false. However, Visual Studio 2005 treats this control differently from Visual Studio 2003: When a Label control is added to a form, its AutoSize property is automatically set to TRue. The effect is that it appears that the default has changed from false to TRue. This is helpful because it is more usual to want Label controls to be autosized on a localized form. Note that the LinkLabel control inherits from Label, so the same change applies to LinkLabel controls.

A similar effect can be seen for CheckBox and RadioButton controls. These controls do not have an AutoSize property in the .NET Framework 1.1. In the .NET Framework 2.0, the default value for AutoSize for CheckBoxes and RadioButtons is false, but Visual Studio 2005 automatically sets it to true.

AutoSizeMode Property

Some controls (Button, DataGridViewColumn, Form, GroupBox, Panel, Splitter-Panel, TabPage, ToolStripContentPanel, UserControl) have a new property called AutoSizeMode that can be set to determine whether the control should automatically grow and shrink as necessary or grow only as necessary. See the "Auto-SizeMode" section in Chapter 8.

AutoEllipsis Property

Some controls (Button, CheckBox, Label, RadioButton) have a new AutoEllipsis property, which automatically displays an ellipsis in the text when there is insufficient room to display the whole text. This is useful for controls that must be localized but whose size must not change (such as controls on a sculpted form). The full text is still available as a ToolTip. See the "AutoEllipsis" section in Chapter 8.

RightToLeftLayout Property

The Form control, together with a number of other Windows Forms controls, now has a RightToLeftLayout property. This Boolean property is used in conjunction with the RightToLeft property and takes effect only when RightToLeft is Yes. Its purpose is to relocate controls within the form so that the controls appear as if they have been laid out correctly for a right-to-left language instead of a left-to-right language. In addition, it correctly mirrors a form's title bar so that the System Menu, Close, Maximize, and Minimize buttons are repositioned correctly. See the "Right-to-Left Languages and Mirroring in Windows Forms Applications" section of Chapter 7, "Middle East and East Asian Cultures," for more details.

TableLayoutPanel and FlowLayoutPanel Controls

The .NET Framework 2.0 includes two new controls, TableLayoutPanel and FlowLayoutPanel, which bring the power of HTML's table and flow layout to Windows Forms. These are significant controls and can have a considerable impact on the way you design your forms for localization and the subsequent role that a translator/localizer might take. Using these controls means that your forms can automatically adapt to controls that resize as a consequence of their text changing size. Well-designed forms, therefore, do not need to be redesigned for different cultures, and a single form can fit all cultures. This drastically reduces the localization effort. See the "TableLayoutPanel and FlowLayoutPanel" section in Chapter 8.

BackgroundWorker

Windows Forms 2.0 introduces a new component called BackgroundWorker, which simplifies moving work to a background thread. This control is relevant to internationalization because, unlike the primitive THRead class that it replaces, Back-groundWorker does not provide you with direct access to the background thread upon which it is based. You can still set the BackgroundWorker's Thread's CurrentCulture and CurrentUICulture, but these must be set in the DoWork event handler:

 public void BeginBackgroundWorker() {     BackgroundWorker backgroundWorker = new BackgroundWorker();     backgroundWorker.DoWork +=         new DoWorkEventHandler(backgroundWorker_DoWork);     backgroundWorker.RunWorkerAsync(); } void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {     Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");     Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");     // do some work } 


WinRes

WinRes in the .NET Framework 1.1 SDK is difficult to use, for several reasons. WinRes in the .NET Framework 2.0 SDK is considerably improved, so if you rejected this tool previously, you should take a fresh look at it in 2.0 for small to medium-sized projects (for large projects, consider using one of the commercially available tools).

First and foremost, WinRes now understands the resx files that Visual Studio 2005 creates. It supports two file modes: Visual Studio File Mode and Single File Mode (the only mode used in WinRes 1.1). This means that you can read and write resx files in both Visual Studio 2005 and also WinRes 2.0 without having to commit to one tool.

WinRes 2.0 has significantly better error reporting. WinRes 1.1 had a handful of cryptic and unhelpful error messages, which lead to a lot of thrashing around trying to identify the real problem. WinRes 2.0 has more descriptive error messages.

WinRes 2.0 is more resilient than its predecessor. WinRes 1.1 refused to load a form if it found a single fault on the form. WinRes 2.0 loads all that it can load and reports the problems about the failed components.

WinRes 2.0 supports loading forms that inherit from other forms when the controls on those other forms have public visibility. Although this support is not absolute, it is considerably better than WinRes 1.1's nonexistent support.

Finally, WinRes 2.0 offers many of the same design and productivity improvements that you see in Visual Studio 2005's Forms Designer (e.g., snap lines).

See the "Windows Resource Localization Editor (WinRes)" section in Chapter 4.




.NET Internationalization(c) The Developer's Guide to Building Global Windows and Web Applications
.NET Internationalization: The Developers Guide to Building Global Windows and Web Applications
ISBN: 0321341384
EAN: 2147483647
Year: 2006
Pages: 213

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net