Search This Blog

Enable and Disable Button VB6 code

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:
  1. PrivateSub Form_Load()
  2. EnableCloseButton me.hWnd, false
  3. End Sub
And to re-enable it later:
  1. private Sub Command1_Click()
  2. EnableCloseButton me.hWnd, true
  3. End Sub