Close button  
Author Message
VBAddict





PostPosted: Visual Basic Express Edition, Close button Top

How can i disable or make it invisible the "X" button located at the upper right of the form


Visual Studio Express Editions40  
 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, Close button Top

you have a couple of options.

1) set the FormBorderStyle to None, but would of course make the form look flat

2) use the Win32 API to disable the button, try this:

 



imports System.Runtime.InteropServices
..
..
<DllImport("user32.dll", SetLastError:=true)> private shared function GetSystemMenu(byval hWnd as IntPtr, byval revert as Integer) as IntPtr
End Function
 
<DllImport("user32.dll", SetLastError:=true)> private shared function GetMenuItemCount(byval hmenu as IntPtr) as Integer
End Function
 
<DllImport("user32.dll", SetLastError:=true)> private shared function RemoveMenu(byval hmenu as IntPtr, byval npos as Integer, byval wflags as Integer) as Integer
End Function
 
<DllImport("user32.dll", SetLastError:=true)> private shared function DrawMenuBar(byval hWnd as IntPtr) as Integer
End Function
 
private Const MF_BYPOSITION as Integer = &H400&
private Const MF_DISABLED as Integer = &H2&
 
//form load event:
 
 
Dim hmenu as IntPtr = GetSystemMenu(Me.Handle, 0)
Dim cnt as Integer = GetMenuItemCount(hmenu)
 
RemoveMenu(hmenu, cnt - 1, MF_DISABLED OR MF_BYPOSITION)
RemoveMenu(hmenu, cnt - 2, MF_DISABLED OR MF_BYPOSITION)
DrawMenuBar(Me.Handle)

 

 

or try this snippet:

 



<DllImport("user32.dll", SetLastError:=true)> private shared function GetSystemMenu(byval hwnd as long, byval bRevert as long) as Long
end function
 
<DllImport("user32.dll", SetLastError:=true)> private shared function RemoveMenu(byval hwnd as long, byval nPosition as long, byval wFlags as long) as Long
end function
..
//form_load event:
 
Const SC_CLOSE = &HF060
Const MF_BYCOMMAND = &H0
Dim hMenu as Long
hMenu = GetSystemMenu(Me.Handle, 0)
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)

 

 

try that and see how it goes, it may not be accurate but hopefully you can fix the syntax for VB.NET as appropriate/needed since I'm trying to convert it from C#



 
 
VBAddict





PostPosted: Visual Basic Express Edition, Close button Top

how about if i want it to become invisible...

 
 
Tall Dude





PostPosted: Visual Basic Express Edition, Close button Top

See:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=517684&SiteID=1



 
 
spotty





PostPosted: Visual Basic Express Edition, Close button Top

Set the controlbox property on the form to false - of course that gets rid of the maximize and minize buttons as well.