15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Windows forms localization Using Visual studio ❘ 585<br />

To show some issues with localization, this program has a picture,<br />

some text, a date, <strong>and</strong> a number. The picture shows a flag that is also<br />

localized. Figure 22-8 shows this form of the application as seen in the<br />

Windows Forms Designer.<br />

The following table lists the values for the Name <strong>and</strong> Text properties<br />

of the Windows Forms elements.<br />

name<br />

xtXT<br />

labelBookOfTheDay Book of the day<br />

labelItemsSold Books sold<br />

textDate<br />

Date<br />

textTitle Professional <strong>C#</strong><br />

textItemsSold 30000<br />

pictureFlag<br />

figure 22-8<br />

In addition to this form, you might want a message box that displays a welcome message; this message<br />

might change depending on the current time of day. This example demonstrates that the localization for<br />

dynamically created dialogs must be done differently. In the method WelcomeMessage(), display a message<br />

box using MessageBox.Show(). Call the method WelcomeMessage() in the constructor of the form class<br />

BookOfTheDayForm, before the call to InitializeComponent().<br />

Here is the code for the method WelcomeMessage():<br />

public void WelcomeMessage()<br />

{<br />

DateTime now = DateTime.Now;<br />

string message;<br />

if (now.Hour

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!