简体   繁体   English

如何在C#Windows应用程序中强制用户响应消息框

[英]how to force user to respond to message box in c# windows application

I want to show messagebox to the user, such that the user cannot refuse to confirm the message box. 我想向用户显示消息框,以便用户不能拒绝确认消息框。 User should not be allowed to do anything else in the screen until he confirms the messagebox. 除非确认消息框,否则不允许用户在屏幕上执行任何其他操作。 This is a windows based c# application. 这是一个基于Windows的C#应用​​程序。 The main thing is, even if i use windows message box. 最主要的是,即使我使用Windows消息框。 Some times it is hiding behind some screen. 有时它隐藏在某些屏幕后面。 But for my case, i want message box to be on top most whenever it appears. 但就我而言,我希望消息框在出现时始终位于最上方。 I am using some other third party applications, which over rides my message box. 我正在使用其他一些第三方应用程序,这些应用程序超出了我的消息框。 I want to overcome this. 我想克服这个。 How to do this... 这个怎么做...

You might have to define a custom message box (a Form ) and set its TopMost property to true .This will make it on top of ever other window, except other TopMost windows. 您可能需要定义一个自定义消息框(一个Form )并将其TopMost属性设置为true这将使其位于除其他TopMost窗口之外的其他所有窗口之上。

That's assuming you want it on top of other applications too, which I'm not sure it's what you're looking for... 假设您也希望它在其他应用程序之上 ,但我不确定这不是您要查找的内容...

Invoke messagebox inside the constructor of your form. 在表单的构造函数中调用消息框。

  public Form1()
        {
            if (MessageBox.Show(this, "Confirm?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
            }
            else
            {
            }
            InitializeComponent();
        }

OR 要么

Invoke another form instance using ShowDialog() method, 使用ShowDialog()方法调用另一个表单实例,

  public Form1()
        {
           Form2 frm=new Form2();
           frm.ShowDialog(this);
        }

普通的Windows MessageBox()函数应该完全做到这一点,除非我在您的问题中遗漏了一些东西。

显示消息框时,始终指定所有者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM