Skip to content

Commit 479455e

Browse files
committed
add parentWindow arg
1 parent ee7ded1 commit 479455e

File tree

1 file changed

+81
-6
lines changed

1 file changed

+81
-6
lines changed

ModernMessageBoxLib/QModernMessageBox.cs

+81-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
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
{
1314
/// <summary>
14-
/// Get or set the owner of the MessageBoxWindow
15+
/// Get or set the default owner of the MessageBoxWindow
1516
/// </summary>
16-
public static System.Windows.Window ParentWindow { get; set; }
17+
public static Window GlobalParentWindow { get; set; }
1718

1819
/// <summary>
1920
/// Get or set the text of the buttons
@@ -45,6 +46,7 @@ public static class QModernMessageBox
4546
/// <summary>
4647
/// Create and show a Modern Messagebox
4748
/// </summary>
49+
/// <param name="parentWindow">the owner of the messagebox window</param>
4850
/// <param name="msg">Message</param>
4951
/// <param name="title">Title</param>
5052
/// <param name="btns">
@@ -54,14 +56,16 @@ public static class QModernMessageBox
5456
/// The icon to show
5557
/// </param>
5658
/// <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)
5963
{
6064
var msgBox = new ModernMessageBox(msg, title, icon) {
6165
Background = GlobalBackground,
6266
Foreground = GlobalForeground,
67+
Owner = parentWindow,
6368
};
64-
msgBox.Owner = ParentWindow;
6569
switch (btns) {
6670
case QModernMessageBoxButtons.Ok:
6771
msgBox.Button1Text = MainLang.Ok;
@@ -111,6 +115,23 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
111115
return msgBox.Result;
112116
}
113117

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+
114135
/// <summary>
115136
/// Create and show a metro messagebox with a warning sign and a "OK" button
116137
/// </summary>
@@ -119,6 +140,15 @@ public static ModernMessageboxResult Show(string msg, string title, QModernMessa
119140
public static void Warning(string msg, string title) =>
120141
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
121142

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+
122152
/// <summary>
123153
/// Create and show a metro messagebox with an infomation sign and a "OK" button
124154
/// </summary>
@@ -127,6 +157,15 @@ public static void Warning(string msg, string title) =>
127157
public static void Info(string msg, string title) =>
128158
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
129159

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+
130169
/// <summary>
131170
/// Create and show a metro messagebox with an error sign and a "OK" button
132171
/// </summary>
@@ -135,6 +174,15 @@ public static void Info(string msg, string title) =>
135174
public static void Error(string msg, string title) =>
136175
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Error);
137176

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+
138186
/// <summary>
139187
/// Create and show a metro messagebox with a question sign and a "OK" button
140188
/// </summary>
@@ -143,13 +191,31 @@ public static void Error(string msg, string title) =>
143191
public static void Question(string msg, string title) =>
144192
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Question);
145193

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+
146203
/// <summary>
147204
/// Create and show a metro messagebox with a "OK" button
148205
/// </summary>
149206
/// <param name="msg">Message</param>
150207
/// <param name="title">Title</param>
151208
public static void None(string msg, string title) => Show(msg, title, QModernMessageBoxButtons.Ok);
152209

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+
153219
/// <summary>
154220
/// Create and show a metro messagebox with a done sign and a "OK" button
155221
/// </summary>
@@ -158,6 +224,15 @@ public static void Question(string msg, string title) =>
158224
public static void Done(string msg, string title) =>
159225
Show(msg, title, QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Done);
160226

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+
161236
/// <summary>
162237
/// Define the buttons on the QModernMessageBox
163238
/// </summary>

0 commit comments

Comments
 (0)