How to make the close button and maximize button disappear?

How to make the close button and maximize button disappear?

Post by Altramagnu » Wed, 07 Jul 2004 20:14:46


I need a window with only the minimize button on the top right corner.
How do I make the close button and maximize button disappear?
I am using C#.

THanks.
 
 
 

How to make the close button and maximize button disappear?

Post by hirf-spam- » Wed, 07 Jul 2004 21:23:41

* "Altramagnus" < XXXX@XXXXX.COM > scripsit:

If you want to keep the minimize button visible, that's not possible.
Nevertheless, you can set the 'MaximizeButton' property of the form to
'False' and disable the close button:

\\\
Private Declare Auto Function GetSystemMenu Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal bRevert As Int32 _
) As IntPtr

Private Declare Auto Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As IntPtr _
) As Int32

Private Declare Auto Function DrawMenuBar Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Int32

Private Declare Auto Function RemoveMenu Lib "user32.dll" ( _
ByVal hMenu As IntPtr, _
ByVal nPosition As Int32, _
ByVal wFlags As Int32 _
) As Int32

Private Const MF_BYPOSITION As Int32 = &H400
Private Const MF_REMOVE As Int32 = &H1000

Private Sub RemoveCloseButton(ByVal frmForm As Form)
Dim hMenu As IntPtr, n As Int32
hMenu = GetSystemMenu(frmForm.Handle, 0)
If Not hMenu.Equals(IntPtr.Zero) Then
n = GetMenuItemCount(hMenu)
If n > 0 Then
RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
DrawMenuBar(frmForm.Handle)
End If
End If
End Sub
///

--
Herfried K. Wagner [MVP]
<URL: http://www.yqcomputer.com/ ;

 
 
 

How to make the close button and maximize button disappear?

Post by Mick Doher » Wed, 07 Jul 2004 21:54:06

Hello Herfied,

You can achieve the same effect without InterOp.
Set MaximizeButton to False and edit CreateParams as follows:

\\\vb.net\\\
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
Const CS_DBLCLKS As Integer = &H8
Const CS_NOCLOSE As Integer = &H200
cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
Return cp
End Get
End Property
///

\\\C#\\\
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
const int CS_DBLCLKS = 0x8;
const int CS_NOCLOSE = 0x200;
cp.ClassStyle=CS_DBLCLKS | CS_NOCLOSE;
return cp;
}
}
///
--
Mick Doherty
http://www.yqcomputer.com/


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.yqcomputer.com/ ).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004