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