1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// --------------------------------------------------------------------------------------------------------------------
// <info file="CsharpInputBox.cs" author="RundR" version="1.1.0.0" releaseDate="30.08.2011">
// (c) by RundR
// </info>
// --------------------------------------------------------------------------------------------------------------------
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace IBNS
{
class InputBox
{
Window dialogWindow;
InputBoxResult PressedButton;
private enum InputBoxResult
{
Ok = 0,
Cancel = 1,
Default = 2,
}
public string ShowDialog(string caption, string description, string defaultInputValue)
{
var rootPanel = new StackPanel { Margin = new Thickness(5) };
var AA = new StackPanel { Orientation = Orientation.Horizontal };
var AB = new StackPanel { };
rootPanel.Children.Add(AA);
rootPanel.Children.Add(AB);
var AAA = new StackPanel { Width = 215 };
var AAB = new StackPanel { Width = 75, Orientation = Orientation.Vertical };
AA.Children.Add(AAA);
AA.Children.Add(AAB);
dialogWindow = new Window
{
Title = caption,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
WindowStyle = WindowStyle.ThreeDBorderWindow,
ResizeMode = ResizeMode.NoResize,
Width = 310,
Height = 120,
Content = rootPanel,
ShowInTaskbar = false,
Background = Brushes.LightGray
};
var descriptionText = new TextBlock { Text = description, TextWrapping = TextWrapping.Wrap, MaxHeight = 50 };
var inputTextBox = new TextBox { Text = defaultInputValue };
var OkButton = new Button { Content = "Ok", Margin = new Thickness(0, 0, 0, 5) };
var CancelButton = new Button { Content = "Abbrechen", Margin = new Thickness(0, 0, 0, 5) };
OkButton.Click += new RoutedEventHandler(OkButton_Click);
CancelButton.Click += new RoutedEventHandler(CancelButton_Click);
dialogWindow.KeyDown += new System.Windows.Input.KeyEventHandler(dialogWindow_KeyDown);
AAA.Children.Add(descriptionText);
AB.Children.Add(inputTextBox);
AAB.Children.Add(OkButton);
AAB.Children.Add(CancelButton);
PressedButton = InputBoxResult.Default;
dialogWindow.ShowDialog();
switch (PressedButton)
{
case InputBoxResult.Ok:
return inputTextBox.Text;
case InputBoxResult.Cancel:
return string.Empty;
default:
return string.Empty;
}
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
PressedButton = InputBoxResult.Ok;
dialogWindow.Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
PressedButton = InputBoxResult.Cancel;
dialogWindow.Close();
}
private void dialogWindow_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
switch (e.Key)
{
case System.Windows.Input.Key.Enter:
PressedButton = InputBoxResult.Ok;
dialogWindow.Close();
break;
case System.Windows.Input.Key.Escape:
PressedButton = InputBoxResult.Cancel;
dialogWindow.Close();
break;
}
}
}
}
|