1 using System;
2 using System.Windows;
3
4 class HelloWindow : Window
5 {
6 public HelloWindow() : base("Hello"), numHellos(0), color(0u, 0x5au, 0xb4u), brush(color), fontFamily(FontFamily.GenericSansSerif()), font(fontFamily, 14.0f)
7 {
8 Size s = GetSize();
9 Size defaultButtonSize = ScreenMetrics.Get().DefaultButtonSize();
10 Size defaultControlSpacing = ScreenMetrics.Get().DefaultControlSpacing();
11 int x = s.w - defaultButtonSize.w - defaultControlSpacing.w;
12 int y = s.h - defaultButtonSize.h - defaultControlSpacing.h;
13
14 UniquePtr<Button> helloButton(new Button(ButtonCreateParams(ButtonControlCreateParams(
15 ControlCreateParams().SetText("Hello").SetLocation(Point(x, y)).SetSize(defaultButtonSize).
16 SetAnchors(cast<Anchors>(Anchors.bottom | Anchors.right))))));
17 helloButton->ClickEvent().AddHandler(HelloButtonClick);
18 AddChild(helloButton.Release());
19 PaintEvent().AddHandler(Paint);
20 }
21 private void HelloButtonClick()
22 {
23 ++numHellos;
24 Invalidate();
25 }
26 private void Paint(PaintEventArgs& args)
27 {
28 try
29 {
30 PointF origin(10.0f, 10.0f);
31 for (int i = 0; i < numHellos; ++i;)
32 {
33 args.graphics.DrawStringChecked("Hello, World!", font, origin, brush);
34 origin.y = origin.y + font.GetHeight(args.graphics);
35 }
36 }
37 catch (const Exception& ex)
38 {
39 MessageBox.Show(ex.Message(), "Error", this, cast<MessageBoxType>(MessageBoxType.MB_OK | MessageBoxType.MB_ICONSTOP));
40 }
41 }
42 private int numHellos;
43 private Color color;
44 private SolidBrush brush;
45 private FontFamily fontFamily;
46 private Font font;
47 private Button* helloButton;
48 }
49
50 int main()
51 {
52 try
53 {
54 HelloWindow helloWindow;
55 return Application.Run(helloWindow);
56 }
57 catch (const Exception& ex)
58 {
59 MessageBox.Show(ex.Message(), "Error", null, cast<MessageBoxType>(MessageBoxType.MB_OK | MessageBoxType.MB_ICONSTOP));
60 try
61 {
62 System.IO.StreamWriter errorWriter = System.IO.File.CreateText("error.txt");
63 errorWriter << ex.ToString() << endl();
64 }
65 catch (const Exception& innerEx)
66 {
67 }
68 return 1;
69 }
70 return 0;
71 }