1 using System;
2 using System.Windows;
3
4 class HelloWindow : Window
5 {
6 public HelloWindow() : base("Hello"), numHellos(0), color(0u, 90u, 180u), brush(color), fontFamily(FontFamily.GenericSansSerif()), font(fontFamily, 14.000000f)
7 {
8 if (brush.Error())
9 {
10 SetErrorId(brush.GetErrorId());
11 return;
12 }
13 if (fontFamily.Error())
14 {
15 SetErrorId(fontFamily.GetErrorId());
16 return;
17 }
18 if (font.Error())
19 {
20 SetErrorId(font.GetErrorId());
21 return;
22 }
23 Size s = GetSize();
24 Size defaultButtonSize = ScreenMetrics.Get().DefaultButtonSize();
25 Size defaultControlSpacing = ScreenMetrics.Get().DefaultControlSpacing();
26 int x = s.w - defaultButtonSize.w - defaultControlSpacing.w;
27 int y = s.h - defaultButtonSize.h - defaultControlSpacing.h;
28
29 UniquePtr<Button> helloButton(new Button(ButtonCreateParams(ButtonControlCreateParams(
30 ControlCreateParams().SetText("Hello").SetLocation(Point(x, y)).SetSize(defaultButtonSize).
31 SetAnchors(cast<Anchors>(Anchors.bottom | Anchors.right))))));
32 if (helloButton->Error())
33 {
34 SetErrorId(helloButton->GetErrorId());
35 return;
36 }
37 helloButton->ClickEvent().AddHandler(HelloButtonClick);
38 auto result = AddChild(helloButton.Release());
39 if (result.Error())
40 {
41 SetErrorId(result.GetErrorId());
42 return;
43 }
44 PaintEvent().AddHandler(Paint);
45 }
46 private void HelloButtonClick(ClickEventArgs& args)
47 {
48 ++numHellos;
49 auto result = Invalidate();
50 if (result.Error())
51 {
52 args.errorId = result.GetErrorId();
53 return;
54 }
55 }
56 private void Paint(PaintEventArgs& args)
57 {
58 PointF origin(10.000000f, 10.000000f);
59 float height = font.GetHeight(args.graphics);
60 for (int i = 0; i < numHellos; ++i;)
61 {
62 auto drawStringResult = args.graphics.DrawString("Hello, World!", font, origin, brush);
63 if (drawStringResult.Error())
64 {
65 string errorMessage = drawStringResult.GetErrorMessage();
66 MessageBox.Show(errorMessage, "error");
67 return;
68 }
69 else
70 {
71 origin.y = origin.y + height;
72 }
73 }
74 }
75 private int numHellos;
76 private Color color;
77 private SolidBrush brush;
78 private FontFamily fontFamily;
79 private Font font;
80 private Button* helloButton;
81 }
82
83 int main()
84 {
85 HelloWindow helloWindow;
86 if (helloWindow.Error())
87 {
88 string errorMessage = GetErrorMessage(helloWindow.GetErrorId());
89 MessageBox.Show(errorMessage, "error");
90 return 1;
91 }
92 return Application.Run(helloWindow);
93 }