flynn Posted March 15, 2006 Posted March 15, 2006 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 Quote
Cags Posted March 15, 2006 Posted March 15, 2006 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted March 16, 2006 Leaders Posted March 16, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.