Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using this code to disable the "X" (close) control on a .Net 2.0 form, but is there a better way? I'd rather use code from the .Net framework instead of VB6 code.

 

Public Class Form1
   Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
   Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

   Public Const SC_CLOSE = &HF060&
   Public Const MF_BYCOMMAND = &H0&


   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
       Dim SysMenuHandle As Integer
       SysMenuHandle = GetSystemMenu(Me.Handle().ToInt32(), False)
       RemoveMenu(SysMenuHandle, SC_CLOSE, MF_BYCOMMAND)
   End Sub

End Class

 

tia,

flynn

Posted

  Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       e.Cancel = True
   End Sub

 

Obviously that only stops it working, doesn't stop it showing up.

Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted
The method that you are using is actually Windows API, not necessarily VB6, and this feature is not present in the .Net Framework as far as I know, unless you want to set the ControlBox property to false and lose the Maximize, Minimize, and Close buttons as well as the icon.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...