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