Enable / Disable Forms Close Button

There are times when it is desirable to disable the close button on a form. EnableCloseButton() is a simple function that does just this, and can re-enable the button as well.

Ordinarily it is quite a simple matter to disable a menu item, but VB does not like us doing this to a form’s close button. As a result more work is required to trick VB into thinking that the close option no longer exists if we are to disable the button. This is all hidden from the developer in one simple function.



For example, to disable a form’s close button on loading:

    PrivateSub Form_Load()
        EnableCloseButton me.hWnd, false
    End Sub

And to re-enable it later:

    private Sub Command1_Click()
        EnableCloseButton me.hWnd, true
    End Sub

EnableCloseButton() was written in VB6

Download Zipped Project File (3k)

More by Author

Must Read