Jump to content

Recommended Posts

Posted

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
Posted

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


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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.