2013-05-01 306 views
0

我想删除消息框中的按钮,如(是,是否,OK ...),但不是关闭按钮。我发现没有办法做到这一点,除非删除参数,但我不能这样做,因为我需要添加选项参数到我的消息框。如何删除MessageBox按钮?

+2

您至少需要一个按钮;它是消息框规范的一部分。如果你只是想显示一条信息性消息,比如说在没有用户介入的情况下让它自动消失,那么除了消息框外,你还需要使用别的东西,可能只是一个简单的表单。 – 2013-05-01 15:03:04

回答

2

我同意@NDJ,最简洁最直接的解决方案是基于表单构建自己的消息框。要修改实际的MessageBox,需要很多低级别的Windows API,例如这个example。 (该项目正在修改按钮上的文本,您需要额外的API来隐藏它们;但MessageBox不会调整大小)

*我不建议您使用API​​方法...我是只是告诉你需要多少努力和代码!

6

我认为你唯一的选择是创建一个看起来像一个消息框的自定义窗体。

0

所以,如果你的意思是删除关闭按钮。除非您制作新表格,否则您无法将其删除。如果你想禁用它。复制下面的链接。我多次使用它来禁用消息框中的关闭按钮。

internal const int SC_CLOSE = 0xF060;   //close button's code in windows api 
    internal const int MF_GRAYED = 0x1;    //disabled button status (enabled = false) 
    internal const int MF_ENABLED = 0x00000000;  //enabled button status 
    internal const int MF_DISABLED = 0x00000002; //disabled button status 

    [DllImport("user32.dll")] //Importing user32.dll for calling required function 
    private static extern IntPtr GetSystemMenu(IntPtr HWNDValue, bool Revert); 

    /// HWND: An IntPtr typed handler of the related form 
    /// It is used from the Win API "user32.dll" 

    [DllImport("user32.dll")] //Importing user32.dll for calling required function again 
    private static extern int EnableMenuItem(IntPtr tMenu, int targetItem, int targetStatus);