Jump to content

Recommended Posts

Posted
This is the desired behaviour.

 

I thought the desired behaviour was to only close the form if the cancel button was enabled (if it was a user requested close)

 

err. confused - && or || ?

 

If I'm right, use &&

 

Using || as powdarrmonkey suggests will indeed close the form either way, meaning an alt + F4 will also close it (regardless of whether the cancel button is enabled)

Posted

@Josh - the idea is that when the form loads the button is disabled - foricng the user to read whats on screen

 

They can only close the app once the button has been enabled - until then the application cannot be allowed to close...

Posted
I thought the desired behaviour was to only close the form if the cancel button was enabled (if it was a user requested close)

 

 

No, read the braced section of the if statement. The test is whether to cancel the close action or not, and you want to do this if either

- the button was enabled and has been pressed

- the form is being closed because the OS needs it to, not because the user asked for it to

Posted
No, read the braced section of the if statement. The test is whether to cancel the close action or not, and you want to do this if either

- the button was enabled and has been pressed

- the form is being closed because the OS needs it to, not because the user asked for it to

 

OK maybe I'm misunderstanding, but e.CloseReason == CloseReason.UserClose is true if the user has tried to close the form, not the OS, isn't it?

Posted
OK maybe I'm misunderstanding, but e.CloseReason == CloseReason.UserClose is true if the user has tried to close the form, not the OS, isn't it?

 

Ye-es... and then if this is the case, we cancel the pending close message. Otherwise there was some other reason for closing it (e.g. the machine is shutting down) and we just keep quiet and let it.

Posted
Ye-es... and then if this is the case, we cancel the pending close message.

 

But then !btnClose.Enabled is true if the button is disabled, so we're allowing the form to be closed by the user when the button is still disabled...

Posted
But then !btnClose.Enabled is true if the button is disabled, so we're allowing the form to be closed by the user when the button is still disabled...

 

IIRC - If windows is shutting down, and the app wont close properly, it will "End Task" it anyway so even if the button is disabled - the app will still closeas its an OS call.

 

I think!

Posted
But then !btnClose.Enabled is true if the button is disabled,

 

Ye-es, in which case we cancel the close request because the user shouldn't be able to close it yet...

 

so we're allowing the form to be closed by the user when the button is still disabled...

 

Not so. We are cancelling the user's request to close it if the button is still disabled.

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...