No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / examples / hello-csharp-forms / hello.cs
blob4a224f37d5ee79334b1ddff70ef6194a7a4e21c6
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.
7 using System; /* String, EventHandler */
8 using GNU.Gettext; /* GettextResourceManager */
9 using System.Diagnostics; /* Process */
10 using System.Threading; /* Thread */
11 using System.Drawing; /* Point, Size */
12 using System.Windows.Forms; /* Application, Form, Label, Button */
14 public class Hello {
16 private static GettextResourceManager catalog =
17 new GettextResourceManager("hello-csharp-forms");
19 class HelloWindow : Form {
21 private int border;
22 private Label label1;
23 private Label label2;
24 private Button ok;
26 public HelloWindow () {
27 border = 2;
29 label1 = new Label();
30 label1.Text = catalog.GetString("Hello, world!");
31 label1.ClientSize = new Size(label1.PreferredWidth, label1.PreferredHeight);
32 Controls.Add(label1);
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);
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);
49 Size total = ComputePreferredSizeWithoutBorder();
50 LayoutControls(total.Width, total.Height);
51 ClientSize = new Size(border + total.Width + border, border + total.Height + border);
54 protected override void OnResize(EventArgs ev) {
55 LayoutControls(ClientSize.Width - border - border, ClientSize.Height - border - border);
56 base.OnResize(ev);
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);
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);
74 private void Quit (Object sender, EventArgs ev) {
75 Application.Exit();
79 public static void Main () {
80 Application.Run(new HelloWindow());