.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Disable MessageBox Close button [x] in C#.Net

Posted By: Narayanan     Posted Date: July 18, 2012    Points:5   Category :C#
I am using MessageBox in Project.How to disable MessageBox Close[X] button ?
My MessageBox like this:
[CODE]MessageBox.Show("Are you sure, Do you want to Close this Application?","Application Name",[B]MessageBoxButtons.Ok[/B] );[/CODE]
How to disable MessageBox Close[X] button.
Note:I know, It is possible in MessageBoxButtons.YesNo display button.I know you can create a Custom MessageBox .My Question is why is not possible to MessageBoxButtons.Ok display button?Please Explain me.

Author: Narayanan             
Posted Date: August 01, 2012     Points: 20   

In my Experience this is not possible.But you can try to this way .

MessageBox.Show("Are you sure, Do you want to Close this Application?","Application Name",MessageBoxButtons.YesNo);

 #region Globals

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


Regards, Lakshmi Naraayanan.S
Author: kamlesh             
Posted Date: August 27, 2012     Points: 20   


check below Link


Thanks And Regards.
Kamlesh Nikam
Author: Clintonzz             
Posted Date: March 18, 2014     Points: 20   

Quite new in this field, but you may try to test some UI messagebox:


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend