Skip to content

Commit 811234f

Browse files
authored
Merge pull request #2 from lim0513/master
add Owner Property
2 parents fedfc32 + 479455e commit 811234f

File tree

1 file changed

+84
-3
lines changed

1 file changed

+84
-3
lines changed

ModernMessageBoxLib/QModernMessageBox.cs

+84-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
using System;
2+
using System.Windows;
23
using System.Windows.Input;
34
using System.Windows.Media;
45

56
namespace ModernMessageBoxLib
67
{
78
/// <summary>
89
/// 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
1011
/// </summary>
1112
public static class QModernMessageBox
1213
{
14+
/// <summary>
15+
/// Get or set the default owner of the MessageBoxWindow
16+
/// </summary>
17+
public static Window GlobalParentWindow { get; set; }
18+
1319
/// <summary>
1420
/// Get or set the text of the buttons
1521
/// The default value is in English. If you want other language, you should specify them manully
@@ -40,6 +46,7 @@ public static class QModernMessageBox
4046
/// <summary>
4147
/// Create and show a Modern Messagebox
4248
/// </summary>
49+
/// <param name="parentWindow">the owner of the messagebox window</param>
4350
/// <param name="msg">Message</param>
4451
/// <param name="title">Title</param>
4552
/// <param name="btns">
@@ -49,12 +56,15 @@ public static class QModernMessageBox
4956
/// The icon to show
5057
/// </param>
5158
/// <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)
5463
{
5564
var msgBox = new ModernMessageBox(msg, title, icon) {
5665
Background = GlobalBackground,
5766
Foreground = GlobalForeground,
67+
Owner = parentWindow,
5868
};
5969
switch (btns) {
6070
case QModernMessageBoxButtons.Ok:
@@ -105,6 +115,23 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
105115
return msgBox.Result;
106116
}
107117

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+
108135
/// <summary>
109136
/// Create and show a metro messagebox with a warning sign and a "OK" button
110137
/// </summary>
@@ -113,6 +140,15 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
113140
public static void Warning(string msg, string title) =>
114141
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
115142

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+
116152
/// <summary>
117153
/// Create and show a metro messagebox with an infomation sign and a "OK" button
118154
/// </summary>
@@ -121,6 +157,15 @@ public static void Warning(string msg, string title) =>
121157
public static void Info(string msg, string title) =>
122158
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
123159

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+
124169
/// <summary>
125170
/// Create and show a metro messagebox with an error sign and a "OK" button
126171
/// </summary>
@@ -129,6 +174,15 @@ public static void Info(string msg, string title) =>
129174
public static void Error(string msg, string title) =>
130175
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Error);
131176

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+
132186
/// <summary>
133187
/// Create and show a metro messagebox with a question sign and a "OK" button
134188
/// </summary>
@@ -137,13 +191,31 @@ public static void Error(string msg, string title) =>
137191
public static void Question(string msg, string title) =>
138192
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Question);
139193

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+
140203
/// <summary>
141204
/// Create and show a metro messagebox with a "OK" button
142205
/// </summary>
143206
/// <param name="msg">Message</param>
144207
/// <param name="title">Title</param>
145208
public static void None(string msg, string title) => Show(msg, title, QModernMessageBoxButtons.Ok);
146209

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+
147219
/// <summary>
148220
/// Create and show a metro messagebox with a done sign and a "OK" button
149221
/// </summary>
@@ -152,6 +224,15 @@ public static void Question(string msg, string title) =>
152224
public static void Done(string msg, string title) =>
153225
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Done);
154226

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+
155236
/// <summary>
156237
/// Define the buttons on the QModernMessageBox
157238
/// </summary>

0 commit comments

Comments
 (0)