user2339812
user2339812

Reputation: 13

How to remove MessageBox Buttons?

I want to delete the buttons in a message box such as (yes, YesNo, OK ...), but not the close button. I found no way to do this unless deleting the parameter as well, but I can't do so since I need to add options parameters to my message box.

Upvotes: 1

Views: 5921

Answers (4)

Charlston Mabini Vita
Charlston Mabini Vita

Reputation: 174

So if you mean to remove the close button. There's no way you can remove it unless you make new form. If u want to disable it. Copy this link below. I'm using it many times for the Close Button in the Message Box to be disabled.

    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);

Upvotes: 1

Idle_Mind
Idle_Mind

Reputation: 39132

I agree with @NDJ, the cleanest and most straight forward solution is to build your own message box based on a Form. To modify the actual MessageBox would require lots of low level Windows APIs like in this example. (That project is modifying the Text on the buttons. You would need additional APIs to hide them; the MessageBox wouldn't resize though.)

*I'm not recommending you use the API approach...I'm just showing you how much effort and code it would take!

Upvotes: 3

ddavison
ddavison

Reputation: 29032

According to the C# API for MessageBox's

there is no member for MessageBoxButtons.CLOSE as you specify. Do as NDJ says.

Upvotes: 1

NDJ
NDJ

Reputation: 5194

I think your only option is to create a custom form which looks like a message box.

Upvotes: 7

Related Questions