1 // Example for use of GNU gettext.
2 // Copyright (C) 2003-2004 Free Software Foundation, Inc.
3 // This file is in the public domain.
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 */
16 private static GettextResourceManager catalog
=
17 new GettextResourceManager("hello-csharp-forms");
19 class HelloWindow
: Form
{
26 public HelloWindow () {
30 label1
.Text
= catalog
.GetString("Hello, world!");
31 label1
.ClientSize
= new Size(label1
.PreferredWidth
, label1
.PreferredHeight
);
37 catalog
.GetString("This program is running as process number {0}."),
38 Process
.GetCurrentProcess().Id
);
39 label2
.ClientSize
= new Size(label2
.PreferredWidth
, label2
.PreferredHeight
);
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
);
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
);
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
),
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
) {
79 public static void Main () {
80 Application
.Run(new HelloWindow());