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
{
13
14
/// <summary>
14
- /// Get or set the owner of the MessageBoxWindow
15
+ /// Get or set the default owner of the MessageBoxWindow
15
16
/// </summary>
16
- public static System . Windows . Window ParentWindow { get ; set ; }
17
+ public static Window GlobalParentWindow { get ; set ; }
17
18
18
19
/// <summary>
19
20
/// Get or set the text of the buttons
@@ -45,6 +46,7 @@ public static class QModernMessageBox
45
46
/// <summary>
46
47
/// Create and show a Modern Messagebox
47
48
/// </summary>
49
+ /// <param name="parentWindow">the owner of the messagebox window</param>
48
50
/// <param name="msg">Message</param>
49
51
/// <param name="title">Title</param>
50
52
/// <param name="btns">
@@ -54,14 +56,16 @@ public static class QModernMessageBox
54
56
/// The icon to show
55
57
/// </param>
56
58
/// <param name="playSound">play the system sound when the messageBox show</param>
57
- public static ModernMessageboxResult Show ( string msg , string title , QModernMessageBoxButtons btns ,
58
- 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 )
59
63
{
60
64
var msgBox = new ModernMessageBox ( msg , title , icon ) {
61
65
Background = GlobalBackground ,
62
66
Foreground = GlobalForeground ,
67
+ Owner = parentWindow ,
63
68
} ;
64
- msgBox . Owner = ParentWindow ;
65
69
switch ( btns ) {
66
70
case QModernMessageBoxButtons . Ok :
67
71
msgBox . Button1Text = MainLang . Ok ;
@@ -111,6 +115,23 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
111
115
return msgBox . Result ;
112
116
}
113
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
+
114
135
/// <summary>
115
136
/// Create and show a metro messagebox with a warning sign and a "OK" button
116
137
/// </summary>
@@ -119,6 +140,15 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
119
140
public static void Warning ( string msg , string title ) =>
120
141
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Warning ) ;
121
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
+
122
152
/// <summary>
123
153
/// Create and show a metro messagebox with an infomation sign and a "OK" button
124
154
/// </summary>
@@ -127,6 +157,15 @@ public static void Warning(string msg, string title) =>
127
157
public static void Info ( string msg , string title ) =>
128
158
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Info ) ;
129
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
+
130
169
/// <summary>
131
170
/// Create and show a metro messagebox with an error sign and a "OK" button
132
171
/// </summary>
@@ -135,6 +174,15 @@ public static void Info(string msg, string title) =>
135
174
public static void Error ( string msg , string title ) =>
136
175
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Error ) ;
137
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
+
138
186
/// <summary>
139
187
/// Create and show a metro messagebox with a question sign and a "OK" button
140
188
/// </summary>
@@ -143,13 +191,31 @@ public static void Error(string msg, string title) =>
143
191
public static void Question ( string msg , string title ) =>
144
192
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Question ) ;
145
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
+
146
203
/// <summary>
147
204
/// Create and show a metro messagebox with a "OK" button
148
205
/// </summary>
149
206
/// <param name="msg">Message</param>
150
207
/// <param name="title">Title</param>
151
208
public static void None ( string msg , string title ) => Show ( msg , title , QModernMessageBoxButtons . Ok ) ;
152
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
+
153
219
/// <summary>
154
220
/// Create and show a metro messagebox with a done sign and a "OK" button
155
221
/// </summary>
@@ -158,6 +224,15 @@ public static void Question(string msg, string title) =>
158
224
public static void Done ( string msg , string title ) =>
159
225
Show ( msg , title , QModernMessageBoxButtons . Ok , ModernMessageboxIcons . Done ) ;
160
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
+
161
236
/// <summary>
162
237
/// Define the buttons on the QModernMessageBox
163
238
/// </summary>
0 commit comments