By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!!
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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=e....phx.gbl#link6 )

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

http://groups.google.com/groups?hl=e...close%2Bbutton

http://groups.google.com/groups?hl=e...close%2Bbutton

Take care,

Eric

"KKuser" <a.*@c.d.com> wrote in message
news:Oi*************@tk2msftngp13.phx.gbl...
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!!

Nov 20 '05 #2

P: n/a
* "KKuser" <a.*@c.d.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.