1 // Example for use of GNU gettext.
2 // This file is in the public domain.
4 // Source code of the C#/Forms program.
6 using System; /* String, EventHandler */
7 using GNU.Gettext; /* GettextResourceManager */
8 using System.Diagnostics; /* Process */
9 using System.Threading; /* Thread */
10 using System.Drawing; /* Point, Size */
11 using System.Windows.Forms; /* Application, Form, Label, Button */
15 private static GettextResourceManager catalog =
16 new GettextResourceManager("hello-csharp-forms");
18 class HelloWindow : Form {
25 public HelloWindow () {
29 label1.Text = catalog.GetString("Hello, world!");
30 label1.ClientSize = new Size(label1.PreferredWidth, label1.PreferredHeight);
36 catalog.GetString("This program is running as process number {0}."),
37 Process.GetCurrentProcess().Id);
38 label2.ClientSize = new Size(label2.PreferredWidth, label2.PreferredHeight);
42 Label okLabel = new Label();
43 ok.Text = okLabel.Text = "OK";
44 ok.ClientSize = new Size(okLabel.PreferredWidth + 12, okLabel.PreferredHeight + 4);
45 ok.Click += new EventHandler(Quit);
48 Size total = ComputePreferredSizeWithoutBorder();
49 LayoutControls(total.Width, total.Height);
50 ClientSize = new Size(border + total.Width + border, border + total.Height + border);
53 protected override void OnResize(EventArgs ev) {
54 LayoutControls(ClientSize.Width - border - border, ClientSize.Height - border - border);
58 // Layout computation, part 1: The preferred size of this panel.
59 private Size ComputePreferredSizeWithoutBorder () {
60 int totalWidth = Math.Max(Math.Max(label1.PreferredWidth, label2.PreferredWidth),
62 int totalHeight = label1.PreferredHeight + label2.PreferredHeight + 6 + ok.Height;
63 return new Size(totalWidth, totalHeight);
66 // Layout computation, part 2: Determine where to put the sub-controls.
67 private void LayoutControls (int totalWidth, int totalHeight) {
68 label1.Location = new Point(border, border);
69 label2.Location = new Point(border, border + label1.PreferredHeight);
70 ok.Location = new Point(border + totalWidth - ok.Width, border + totalHeight - ok.Height);
73 private void Quit (Object sender, EventArgs ev) {
78 public static void Main () {
79 Application.Run(new HelloWindow());