| | |
Disable MDI child close button
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 6
Reputation:
Solved Threads: 0
Hi, I would really appreciate some help with disabling the close button (and the system menu's close option) of a MDI child form in C++ .NET. I've scoured the web, and although I can find it in VB .NET, and bits in C#, I can't find anything to help with c++. A step by step guide would be really appreciated as I guess this will involve some API programming, which I have no experience in.
Thanks very much to anyone that can help.
Thanks very much to anyone that can help.
•
•
Join Date: Feb 2005
Posts: 6
Reputation:
Solved Threads: 0
After HOURS and HOURS of trying to fix this, I think I have finally come up with a solution for c++ .NET
! The issue you will notice with my code is that it has been placed in the VisibleChanged and sizechanged functions, instead of the Load function. this is because when visibility is changed on the form, for some reason the buttons were reset. I solved this obviously by activating the remove button function, whenever the form is becoming visible, or sized.
The code is as follows:
1. At the beginning of the file, include this header file:
#include "windows.h"
2. Add an event handler for when the visiblility and size is changed.
3. Add a function with the following code:
if(this->Visible)
{
HMENU test = GetSystemMenu((HWND)this->Handle.ToInt32(), false);
EnableMenuItem(test, SC_CLOSE, MF_GRAYED | MF_BYCOMMAND);
//the values you pass into RemoveMenu are from the file WinUser.h
}
4. Add to event handlers a call to the function above!
5. Thats It!
If anyone can see any improvement to the code, then please go ahead and post it! I added the call to the function, so that the close button would remain disabled, even when the MDI child is maximized.
! The issue you will notice with my code is that it has been placed in the VisibleChanged and sizechanged functions, instead of the Load function. this is because when visibility is changed on the form, for some reason the buttons were reset. I solved this obviously by activating the remove button function, whenever the form is becoming visible, or sized.The code is as follows:
1. At the beginning of the file, include this header file:
#include "windows.h"
2. Add an event handler for when the visiblility and size is changed.
3. Add a function with the following code:
if(this->Visible)
{
HMENU test = GetSystemMenu((HWND)this->Handle.ToInt32(), false);
EnableMenuItem(test, SC_CLOSE, MF_GRAYED | MF_BYCOMMAND);
//the values you pass into RemoveMenu are from the file WinUser.h
}
4. Add to event handlers a call to the function above!
5. Thats It!
If anyone can see any improvement to the code, then please go ahead and post it! I added the call to the function, so that the close button would remain disabled, even when the MDI child is maximized.
•
•
Join Date: Feb 2007
Posts: 2
Reputation:
Solved Threads: 0
One easy way of disable the close button (X) in a form is to create a "base form" that your other form inherits from and in the base form add this code:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
'This Greys out the X and stops close from appearing in the
'Control box on the form
Dim cp As CreateParams = MyBase.CreateParams
Const CS_DBLCLKS As Int32 = &H8
Const CS_NOCLOSE As Int32 = &H200
cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
Return cp
End Get
End Property
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
'This Greys out the X and stops close from appearing in the
'Control box on the form
Dim cp As CreateParams = MyBase.CreateParams
Const CS_DBLCLKS As Int32 = &H8
Const CS_NOCLOSE As Int32 = &H200
cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
Return cp
End Get
End Property
![]() |
Similar Threads
- Disable MDI parent form button from MDI child form (VB.NET)
- MDI child controlBox (VB.NET)
- Disable Close button on form (C++)
- How to disbale Close(X) button in title bar (JavaScript / DHTML / AJAX)
- MDI Child Form Placement (C#)
- Code Snippet: Disable close button (C#)
Other Threads in the ASP.NET Forum
- Previous Thread: listbox multiple selection
- Next Thread: DTS to SSIS
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax appliances application asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form forms grid gridview gudi homeedition hosting iis image javascript jquery list menu mssql multistepregistration nameisnotdeclared novell objects opera order problem ratings redirect registration relationaldatabases rotatepage search security select serializesmo.table sessionvariables silverlight smoobjects sql ssl tracking treeview typeof validatedate validation vb.net virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment wizard xml xsl





