1// Example for use of GNU gettext.
2// Copyright (C) 2003-2004 Free Software Foundation, Inc.
3// This file is in the public domain.
4//
5// Source code of the C#/Forms program.
6
7using System; /* String, EventHandler */
8using GNU.Gettext; /* GettextResourceManager */
9using System.Diagnostics; /* Process */
10using System.Threading; /* Thread */
11using System.Drawing; /* Point, Size */
12using System.Windows.Forms; /* Application, Form, Label, Button */
13
14public class Hello {
15
16  private static GettextResourceManager catalog =
17    new GettextResourceManager("hello-csharp-forms");
18
19  class HelloWindow : Form {
20
21    private int border;
22    private Label label1;
23    private Label label2;
24    private Button ok;
25
26    public HelloWindow () {
27      border = 2;
28
29      label1 = new Label();
30      label1.Text = catalog.GetString("Hello, world!");
31      label1.ClientSize = new Size(label1.PreferredWidth, label1.PreferredHeight);
32      Controls.Add(label1);
33
34      label2 = new Label();
35      label2.Text =
36        String.Format(
37            catalog.GetString("This program is running as process number {0}."),
38            Process.GetCurrentProcess().Id);
39      label2.ClientSize = new Size(label2.PreferredWidth, label2.PreferredHeight);
40      Controls.Add(label2);
41
42      ok = new Button();
43      Label okLabel = new Label();
44      ok.Text = okLabel.Text = "OK";
45      ok.ClientSize = new Size(okLabel.PreferredWidth + 12, okLabel.PreferredHeight + 4);
46      ok.Click += new EventHandler(Quit);
47      Controls.Add(ok);
48
49      Size total = ComputePreferredSizeWithoutBorder();
50      LayoutControls(total.Width, total.Height);
51      ClientSize = new Size(border + total.Width + border, border + total.Height + border);
52    }
53
54    protected override void OnResize(EventArgs ev) {
55      LayoutControls(ClientSize.Width - border - border, ClientSize.Height - border - border);
56      base.OnResize(ev);
57    }
58
59    // Layout computation, part 1: The preferred size of this panel.
60    private Size ComputePreferredSizeWithoutBorder () {
61      int totalWidth = Math.Max(Math.Max(label1.PreferredWidth, label2.PreferredWidth),
62                                ok.Width);
63      int totalHeight = label1.PreferredHeight + label2.PreferredHeight + 6 + ok.Height;
64      return new Size(totalWidth, totalHeight);
65    }
66
67    // Layout computation, part 2: Determine where to put the sub-controls.
68    private void LayoutControls (int totalWidth, int totalHeight) {
69      label1.Location = new Point(border, border);
70      label2.Location = new Point(border, border + label1.PreferredHeight);
71      ok.Location = new Point(border + totalWidth - ok.Width, border + totalHeight - ok.Height);
72    }
73
74    private void Quit (Object sender, EventArgs ev) {
75      Application.Exit();
76    }
77  }
78
79  public static void Main () {
80    Application.Run(new HelloWindow());
81  }
82}
83