1
1
using System ;
2
+ using System . Windows ;
2
3
using System . Windows . Input ;
3
4
using System . Windows . Media ;
4
5
5
6
namespace ModernMessageBoxLib
6
7
{
7
8
/// <summary>
8
9
/// Common usage of ModernMessageBox,
9
- /// Just like using <see cref="System.Windows. MessageBox"/> in WPF or using QMessageBox in QT
10
+ /// Just like using <see cref="MessageBox"/> in WPF or using QMessageBox in QT
10
11
/// </summary>
11
12
public static class QModernMessageBox
12
13
{
14
+ /// <summary>
15
+ /// Get or set the default owner of the MessageBoxWindow
16
+ /// </summary>
17
+ public static Window GlobalParentWindow { get ; set ; }
18
+
13
19
/// <summary>
14
20
/// Get or set the text of the buttons
15
21
/// The default value is in English. If you want other language, you should specify them manully
@@ -40,6 +46,7 @@ public static class QModernMessageBox
40
46
/// <summary>
41
47
/// Create and show a Modern Messagebox
42
48
/// </summary>
49
+ /// <param name="parentWindow">the owner of the messagebox window</param>
43
50
/// <param name="msg">Message</param>
44
51
/// <param name="title">Title</param>
45
52
/// <param name="btns">
@@ -49,12 +56,15 @@ public static class QModernMessageBox
49
56
/// The icon to show
50
57
/// </param>
51
58
/// <param name="playSound">play the system sound when the messageBox show</param>
52
- public static ModernMessageboxResult Show ( string msg , string title , QModernMessageBoxButtons btns ,
53
- ModernMessageboxIcons icon = ModernMessageboxIcons . None , bool playSound = true )
59
+ public static ModernMessageboxResult Show ( Window parentWindow , string msg , string title ,
60
+ QModernMessageBoxButtons btns ,
61
+ ModernMessageboxIcons icon = ModernMessageboxIcons . None ,
62
+ bool playSound = true )
54
63
{
55
64
var msgBox = new ModernMessageBox ( msg , title , icon ) {
56
65
Background = GlobalBackground ,
57
66
Foreground = GlobalForeground ,
67
+ Owner = parentWindow ,
58
68
} ;
59
69
switch ( btns ) {
60
70
case QModernMessageBoxButtons . Ok :
@@ -105,6 +115,23 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
105
115
return msgBox . Result ;
106
116
}
107
117
118
+ /// <summary>
119
+ /// Create and show a Modern Messagebox
120
+ /// </summary>
121
+ /// <param name="msg">Message</param>
122
+ /// <param name="title">Title</param>
123
+ /// <param name="btns">
124
+ /// The bottons to show
125
+ /// </param>
126
+ /// <param name="icon">
127
+ /// The icon to show
128
+ /// </param>
129
+ /// <param name="playSound">play the system sound when the messageBox show</param>
130
+ public static ModernMessageboxResult Show ( string msg , string title , QModernMessageBoxButtons btns ,
131
+ ModernMessageboxIcons icon = ModernMessageboxIcons . None ,
132
+ bool playSound = true ) => Show ( GlobalParentWindow , msg , title , btns , icon ,
133
+ playSound ) ;
134
+
108
135
/// <summary>
109
136
/// Create and show a metro messagebox with a warning sign and a "OK" button
110
137
/// </summary>
@@ -113,6 +140,15 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
113
140
public static void Warning ( string msg , string title ) =>
114
141
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Warning ) ;
115
142
143
+ /// <summary>
144
+ /// Create and show a metro messagebox with a warning sign and a "OK" button
145
+ /// </summary>
146
+ /// <param name="parentWindow">the owner of the messagebox window</param>
147
+ /// <param name="msg">Message</param>
148
+ /// <param name="title">Title</param>
149
+ public static void Warning ( Window parentWindow , string msg , string title ) =>
150
+ Show ( parentWindow , msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Warning ) ;
151
+
116
152
/// <summary>
117
153
/// Create and show a metro messagebox with an infomation sign and a "OK" button
118
154
/// </summary>
@@ -121,6 +157,15 @@ public static void Warning(string msg, string title) =>
121
157
public static void Info ( string msg , string title ) =>
122
158
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Info ) ;
123
159
160
+ /// <summary>
161
+ /// Create and show a metro messagebox with an infomation sign and a "OK" button
162
+ /// </summary>
163
+ /// <param name="parentWindow">the owner of the messagebox window</param>
164
+ /// <param name="msg">Message</param>
165
+ /// <param name="title">Title</param>
166
+ public static void Info ( Window parentWindow , string msg , string title ) =>
167
+ Show ( parentWindow , msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Info ) ;
168
+
124
169
/// <summary>
125
170
/// Create and show a metro messagebox with an error sign and a "OK" button
126
171
/// </summary>
@@ -129,6 +174,15 @@ public static void Info(string msg, string title) =>
129
174
public static void Error ( string msg , string title ) =>
130
175
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Error ) ;
131
176
177
+ /// <summary>
178
+ /// Create and show a metro messagebox with an error sign and a "OK" button
179
+ /// </summary>
180
+ /// <param name="parentWindow">the owner of the messagebox window</param>
181
+ /// <param name="msg">Message</param>
182
+ /// <param name="title">Title</param>
183
+ public static void Error ( Window parentWindow , string msg , string title ) =>
184
+ Show ( parentWindow , msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Error ) ;
185
+
132
186
/// <summary>
133
187
/// Create and show a metro messagebox with a question sign and a "OK" button
134
188
/// </summary>
@@ -137,13 +191,31 @@ public static void Error(string msg, string title) =>
137
191
public static void Question ( string msg , string title ) =>
138
192
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Question ) ;
139
193
194
+ /// <summary>
195
+ /// Create and show a metro messagebox with a question sign and a "OK" button
196
+ /// </summary>
197
+ /// <param name="parentWindow">the owner of the messagebox window</param>
198
+ /// <param name="msg">Message</param>
199
+ /// <param name="title">Title</param>
200
+ public static void Question ( Window parentWindow , string msg , string title ) =>
201
+ Show ( parentWindow , msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Question ) ;
202
+
140
203
/// <summary>
141
204
/// Create and show a metro messagebox with a "OK" button
142
205
/// </summary>
143
206
/// <param name="msg">Message</param>
144
207
/// <param name="title">Title</param>
145
208
public static void None ( string msg , string title ) => Show ( msg , title , QModernMessageBoxButtons . Ok ) ;
146
209
210
+ /// <summary>
211
+ /// Create and show a metro messagebox with a "OK" button
212
+ /// </summary>
213
+ /// <param name="parentWindow">the owner of the messagebox window</param>
214
+ /// <param name="msg">Message</param>
215
+ /// <param name="title">Title</param>
216
+ public static void None ( Window parentWindow , string msg , string title ) =>
217
+ Show ( parentWindow , msg , title , QModernMessageBoxButtons . Ok ) ;
218
+
147
219
/// <summary>
148
220
/// Create and show a metro messagebox with a done sign and a "OK" button
149
221
/// </summary>
@@ -152,6 +224,15 @@ public static void Question(string msg, string title) =>
152
224
public static void Done ( string msg , string title ) =>
153
225
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Done ) ;
154
226
227
+ /// <summary>
228
+ /// Create and show a metro messagebox with a done sign and a "OK" button
229
+ /// </summary>
230
+ /// <param name="parentWindow">the owner of the messagebox window</param>
231
+ /// <param name="msg">Message</param>
232
+ /// <param name="title">Title</param>
233
+ public static void Done ( Window parentWindow , string msg , string title ) =>
234
+ Show ( parentWindow , msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Done ) ;
235
+
155
236
/// <summary>
156
237
/// Define the buttons on the QModernMessageBox
157
238
/// </summary>
0 commit comments