[英]MessageBox not showing on event
I have a program in which I show a (System.Windows) MessageBox on an event but it doesn't show up.我有一个程序,在该程序中我在事件中显示(System.Windows)MessageBox,但它没有显示。 Please notice that I am pretty sure that this worked on a previous update of VS2019 but not on Version 16.11.5 and on VS2022RC.请注意,我很确定这适用于 VS2019 的先前更新,但不适用于 16.11.5 版和 VS2022RC。
I have also searched for some hints but nothing came out.我也搜索了一些提示,但没有任何结果。 So either I did some blatant mistake or this is something new.所以要么我犯了一些明显的错误,要么这是新事物。
I don't think I can provide any other additional information for I think that this might be misleading.我认为我无法提供任何其他额外信息,因为我认为这可能会产生误导。
Thanks for helping Patrick感谢您帮助帕特里克
MessageBox.Show(string)
and any of it's overloads that do not take a IWin32Window
create a non-modal window. MessageBox.Show(string)
及其任何不采用IWin32Window
的重载都会创建非模态窗口。 This message box then may show up behind other windows or eventually not at all (not sure why the later, but maybe it's outside the screen or so).这个消息框可能会出现在其他窗口后面,或者最终根本不显示(不知道为什么是后者,但可能它在屏幕之外)。 To prevent that, always use an overload with IWin32Window
as first argument.为防止出现这种情况,请始终使用IWin32Window
作为第一个参数的重载。 In a simple WinForms app, this is typically the form calling the Show()
method, so the argument can just be this
.在一个简单的 WinForms 应用程序中,这通常是调用Show()
方法的表单,因此参数可以是this
。
TL;DR TL; 博士
Change改变
MessageBox.Show("Message");
to到
MessageBox.Show(this, "Message");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.