Glossary
The remainder of this chapter shows how to mirror Web Forms, Windows Forms, and message boxes. As was true for Web content, the DIR attribute can be used for mirroring text in Web Forms. The RightToLeft property-from the Control class-is valuable for providing RTL support for Windows Forms, whereas the MessageBox class supports RTL and mirroring for message boxes. In the sections that follow, you will learn how to take advantage of this support.
In Microsoft Visual Studio .NET, you can create ASP.NET applications by using either Microsoft Visual Basic .NET or Microsoft Visual C# .NET. The guidelines that you should follow are basically the same as those you have just seen for mirroring Web content. When you design Arabic Web Forms pages, the best way to make text flow from right to left is to use the DIR attribute. As with Web content, this attribute is usually placed in the <HTML> tag or the <BODY> tag. Controls and HTML elements on the page then inherit the specified direction.
You can set the DIR attribute at a DOCUMENT object level. All the controls on the form will inherit the same settings. However, the DIR attribute can be used individually with other tags such as <TABLE> and in Web Forms controls, as in the following example, which allows items to be displayed from right to left:
<TABLE dir="rtl" ...> <asp:TextBox dir="rtl" ...>
Glossary
Windows applications created in the .NET Framework allow you to access operating-system services and to take advantage of other benefits that your user's computing environment provides. Also, you can access data using ADO.NET. Additionally, GDI+ allows you to do advanced drawing and painting within your forms. (For more information on GDI+, see Chapter 13, "Graphics Device Interface Plus.") Finally, your Windows applications can make calls to methods exposed through XML Web services.
Windows Forms can be standard windows, multiple-document interface (MDI) windows, dialog boxes, or display surfaces for graphical routines. The easiest way to define the UI for a form is to place controls on its surface. Forms are objects that have several functions. The objects expose properties that define the forms' appearance, methods which define their behavior, and events which define their interaction with the user. Windows Forms are controls because they inherit from the Control class. This class has a key property for RTL support-the RightToLeft property-which specifies whether the text is displayed from right to left. The form itself supports the RightToLeft property, as do all your controls.
The RightToLeft property takes one of the following values, as shown in Table 8-1.
Table 8-1 Values for the RightToLeft property.
Value | Description |
Inherit | The direction in which the text is rendered is inherited from the parent control. |
No | The text is rendered from left to right. This is the default value. |
Yes | The text is rendered from right to left. |
The effect of the RightToLeft property can differ slightly from one control to another, as shown later in Table 8-2 below. In the Form object, when you set the RightToLeft property to Yes, text displayed in the form's title bar is right-aligned and has an RTL reading order.
What about design time? The Windows Forms Designer takes into account the effects of the RightToLeft property on controls. For example, when you set the RightToLeft property of the form to Yes, the property automatically updates the display of the form in the designer, so that the form's caption appears in the title bar right-aligned, as at run time. When the RightToLeft property value is set to RightToLeft.Yes, the horizontal alignment of the control's elements is reversed, yet the elements' alignment values are unchanged. For example, in a TextBox control with the TextAlign property value of HorizontalAlignment.Left, text is displayed right-aligned, but the property value remains HorizontalAlignment.Left. However, if the RightToLeft property value is set to RightToLeft.Yes and if the TextAlign property is set to HorizontalAlignment.Right, the text is displayed left-aligned.
Windows Forms don't support mirroring directly, as they do the RightToLeft property. Instead, you create your own controls to be displayed as you need. You can develop your own RTLTreeview control, for example, which inherits from the Treeview control and changes its style to be mirrored.
On some occasions, you might want to create a basic form with settings and properties such as a watermark or a certain control layout that you will then use again within a project. Each new form can contain modifications to the original form template. The solution is to use Windows Forms inheritance, which is a feature offered with the .NET Framework class library. For example, using inheritance you can build your own mirrored form by inheriting from the System.Windows.Forms.Form class and changing the window style of System.-Windows.Forms.Form.
Table 8-2 on the following page explains how the RightToLeft property affects the Windows Forms controls and which of them need to be mirrored. The common effect of setting the RightToLeft property to Yes on all controls is that the base-text embedding (in other words, the overall direction of text rendering) is assumed to be right to left. Table 8-2 explains how the RightToLeft property affects the Windows Forms controls and indicates which of them need mirroring.
Table 8-2 Explains how the RightToLeft property affects the Windows Forms controls and indicates which of them need mirroring.
Control or Component | Right-to-Left Effect | Require Mirroring |
Button | Sets the RTL reading order. | No |
CheckBox | The check box is displayed on the right side of the text. | No |
CheckedListBox | All the check boxes are displayed on the right side of the text. | No |
ColorDialog | Not affected; depends on the language of the operating system. | No |
ComboBox | Items in combo-box control are right-aligned. | No |
ContextMenu | Appears right-aligned with RTL reading order. | No |
DataGrid | Appears right-aligned with RTL reading order. | No |
DateTimePicker | Not affected; depends on the language of the operating system. | No |
DomainUpDown | Left-aligns the up and down buttons. | No |
ErrorProvider | Not supported. | No |
FontDialog | Depends on the language of the operating system. | No |
GroupBox | The caption of the GroupBox is displayed right-aligned and allows all the contained controls to inherit this property. | No |
VScrollBar | Displayed on the left side rather than right side of scrollable controls. | No |
HScrollBar | Start with the scroll box right-aligned. | No |
ImageList | Not required. | No |
Label | Displayed right-aligned. | No |
LinkLabel | Displayed right-aligned. | No |
ListBox | Items in list box control are right-aligned. | No |
ListView | Sets the reading order to RTL, while the elements stay left-aligned. | Yes |
MainMenu | Displayed right-aligned with RTL reading order, during run time only and not in design time. | No |
MonthCalendar | Not affected; depends on the language of the operating system. | No |
NotifyIcon | Not supported. | No |
NumericUpDown | Up and down buttons are left-aligned. | No |
OpenFileDialog | Not affected; depends on the language of the operating system. | No |
PageSetupDialog | Not affected; depends on the language of the operating system. | No |
Panel | Allows all the contained controls to inherit this property. | Yes |
PictureBox | Not supported. | No |
PrintDialog | Not affected; depends on the language of the operating system. | No |
PrintDocument | The vertical scroll bar becomes left-aligned and the horizontal scroll bar starts from the left. | No |
PrintPreview | Not affected by this property. | Yes |
PrintPreviewDialog | Text displayed in the title bar of a form is right-aligned. | No |
ProgressBar | Not affected by this property. | Yes |
RadioButton | The radio button is displayed on the right side of the text. | No |
RichTextBox | Control elements that include text are displayed from right to left with RTL reading order. | No |
SaveFileDialog | Not affected; depends on the language of the operating system. | No |
Splitter | Not supported. | No |
StatusBar | The text in the panels aligned to right with RTL reading order. | Yes |
TabControl | Not affected by this property. | Yes |
TextBox | Displays text from right to left with RTL reading order. | No |
Timer | Not required. | No |
ToolBar | Not affected by this property. | Yes |
ToolTip | Sets the RTL reading order. | No |
TrackBar | The scroll bar or track bar starts from the right side of the screen. | No |
TreeView | Sets the RTL reading order only. | Yes |
As its name suggests, the MessageBox class represents the message box; the Show method of this class displays a message box that can contain text, buttons, and symbols that inform and instruct the user. The MessageBox class fully supports RTL reading order and mirroring. The Show method of the MessageBox class takes constants defined in the MessageBoxOptions enumeration as parameters. These constants include RtlReading and RightAlign, both of which enable the message box to display bidirectional text. The following code illustrates how to display an Arabic message box:
[Visual Basic ] MessageBox.Show("...", "", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading Or MessageBoxOptions.RightAlign)
RtlReading is responsible for ensuring that the text in the message box is displayed with RTL reading order, with mirroring applied. RightAlign allows the text to be right-aligned only, but does not enforce RTL reading order or mirroring in the message box.