Hitmanpt Posted September 30, 2010 at 08:21 PM Report #348608 Posted September 30, 2010 at 08:21 PM Boas pessoal... bem eu tenho o codigo para desactivar o "Close Button" de uma form... mas dps não sei como voltar a activa-lo... alguma ajuda? Aqui está o codigo que o desactiva Public Class Form1 Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean Private Const MF_BYPOSITION = &H400 Private Const MF_REMOVE = &H1000 Private Const MF_DISABLED = &H2 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DisableCloseButton(Me.Handle) 'some code... 'e agora quero o codigo para activar... end sub Public Sub DisableCloseButton(ByVal hwnd As IntPtr) Dim hMenu As IntPtr Dim menuItemCount As Integer hMenu = GetSystemMenu(hwnd, False) menuItemCount = GetMenuItemCount(hMenu) Call RemoveMenu(hMenu, menuItemCount - 1, MF_DISABLED Or MF_BYPOSITION) Call RemoveMenu(hMenu, menuItemCount - 2, MF_DISABLED Or MF_BYPOSITION) Call DrawMenuBar(hwnd) End Sub end class
Weasel Posted October 4, 2010 at 10:31 AM Report #348850 Posted October 4, 2010 at 10:31 AM Eu acho que estás a complicar uma coisa simples que pode ser feita através de um: Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If e.CloseReason = CloseReason.UserClosing Then e.Cancel = True End If End Sub Isto evita que o utilizador feche a aplicação, mas caso o sistema operativo mande fechar (por exemplo encerramento do sistema) ele permite. e com um simples if consegues activar ou desactivar isto tipo If blnButActivo = True Knowledge to the masses
Hitmanpt Posted October 4, 2010 at 05:22 PM Author Report #348899 Posted October 4, 2010 at 05:22 PM Ok obrigado 😉
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now