[VB.Net] How to disable tthe "X" button on the top-right cornor?

K

KKuser

Hello:

I currently use

Me.FormBorderStyle = FormBorderStyle.None

to hide the tile bar, but it looks quite ugly.

It's easy to disable the "X" button using VB6, but I really can't find out
any way to do the same thing using VB.Net.

Thanks!!
 
E

Eric Lemmon

Hello,

A quick solution is to set the Form's ControlBox property to False. This
will hide everything on the title bar except for the title itself. However,
this does not remove the Alt-F4 functionality.

Also, Herfried K. Wagner posted an idea in a previous thread: "I've put
e.Cancel = True in the Form_Closing event and the users can click the 'X'
all day long without closing the form."

(This comes from
http://groups.google.com/groups?hl=...m=emp$d#[email protected]#link6 )

Here are a couple threads with examples of making the API call:

http://groups.google.com/groups?hl=...=UTF-8&oe=UTF-8&q=dotnet+disable+close+button

http://groups.google.com/groups?hl=...=UTF-8&oe=UTF-8&q=dotnet+disable+close+button

Take care,

Eric
 
H

Herfried K. Wagner [MVP]

* "KKuser said:
I currently use

Me.FormBorderStyle = FormBorderStyle.None

to hide the tile bar, but it looks quite ugly.

\\\
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
///
It's easy to disable the "X" button using VB6

I doubt that this was possible in VB6. You were able to hide the
control box there which is possible in VB.NET too, but IMO that doesn't
make much sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top