1 using System;
2 using System.Windows;
3
4 class DialogWindow : Window
5 {
6 public DialogWindow() : base("DialogWindow", DefaultWindowClassStyle(), DialogWindowStyle(), DefaultExtendedWindowStyle(),
7 DefaultWindowBackgroundColor(), "dialog",
8 Point(), Size(ScreenMetrics.Get().MMToHorizontalPixels(70), ScreenMetrics.Get().MMToVerticalPixels(50)), Dock.none, Anchors.none)
9 {
10 Size size = GetSize();
11 Size defaultButtonSize = ScreenMetrics.Get().DefaultButtonSize();
12 Size defaultControlSpacing = ScreenMetrics.Get().DefaultControlSpacing();
13 Size defaultTextBoxSize = ScreenMetrics.Get().DefaultTextBoxSize();
14
15 Point textBoxLoc(defaultControlSpacing.w, defaultControlSpacing.h);
16 Size textBoxSize = defaultTextBoxSize;
17 int textBoxPadding = DefaultControlPadding();
18 int borderWidth = DefaultSingleBorderWidth();
19 Rect textBoxRect(textBoxLoc, textBoxSize);
20 textBoxRect.Inflate(textBoxPadding + borderWidth, textBoxPadding + borderWidth);
21
22 str = "text";
23 UniquePtr<TextBox> textBoxPtr(new TextBox(str));
24 textBox = textBoxPtr.Get();
25 textBox->SelectAll();
26 textBox->TextChangedEvent().AddHandler(TextChanged);
27 UniquePtr<Control> paddedTextBox(new PaddedControl(textBoxPtr.Release()));
28 UniquePtr<Control> borderedTextBox(new BorderedControl(paddedTextBox.Release(), textBoxRect.location, textBoxRect.size, Dock.none, cast<Anchors>(Anchors.top | Anchors.left)));
29 AddChild(borderedTextBox.Release());
30
31 int x = size.w - defaultButtonSize.w - defaultControlSpacing.w;
32 int y = size.h - defaultButtonSize.h - defaultControlSpacing.h;
33 UniquePtr<Button> cancelButtonPtr(new Button("Cancel", Point(x, y), defaultButtonSize, Dock.none, cast<Anchors>(Anchors.bottom | Anchors.right)));
34 cancelButton = cancelButtonPtr.Get();
35 cancelButton->SetDialogResult(DialogResult.cancel);
36 x = x - defaultButtonSize.w - defaultControlSpacing.w;
37 UniquePtr<Button> okButtonPtr(new Button(ButtonStyle.BS_DEFPUSHBUTTON, GetSystemColor(SystemColor.COLOR_BTNFACE), "OK", Point(x, y), defaultButtonSize,
38 Dock.none, cast<Anchors>(Anchors.bottom | Anchors.right)));
39 okButton = okButtonPtr.Get();
40 okButton->SetDialogResult(DialogResult.ok);
41 AddChild(okButtonPtr.Release());
42 AddChild(cancelButtonPtr.Release());
43 SetDefaultButton(okButton);
44 SetCancelButton(cancelButton);
45 }
46 public const string& Str() const
47 {
48 return str;
49 }
50 private void TextChanged()
51 {
52 str = textBox->Text();
53 }
54 private TextBox* textBox;
55 private Button* okButton;
56 private Button* cancelButton;
57 private string str;
58 }
59
60 class MainWindow : Window
61 {
62 public MainWindow() : base("main")
63 {
64 UniquePtr<MenuBar> menuBar(new MenuBar());
65 UniquePtr<MenuItem> dialogMenuItem(new MenuItem("&Dialog"));
66 UniquePtr<MenuItem> newMenuItem(new MenuItem("&New..."));
67 newMenuItem->ClickEvent().AddHandler(NewClick);
68 dialogMenuItem->AddMenuItem(newMenuItem.Release());
69 menuBar->AddMenuItem(dialogMenuItem.Release());
70 AddChild(menuBar.Release());
71 }
72 private void NewClick()
73 {
74 DialogWindow dialog;
75 if (dialog.ShowDialog(*this) == DialogResult.ok)
76 {
77 string s = dialog.Str();
78 MessageBox.Show(s, "Text");
79 }
80 }
81
82 }
83
84 void main()
85 {
86 MainWindow mainWindow;
87 Application.Run(mainWindow);
88 }