xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/examples/hello-csharp-forms/hello.cs (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
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 
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 */
13 
14 public 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 
HelloWindow()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 
OnResize(EventArgs ev)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.
ComputePreferredSizeWithoutBorder()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.
LayoutControls(int totalWidth, int totalHeight)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 
Quit(Object sender, EventArgs ev)74     private void Quit (Object sender, EventArgs ev) {
75       Application.Exit();
76     }
77   }
78 
Main()79   public static void Main () {
80     Application.Run(new HelloWindow());
81   }
82 }
83