Board index » cppbuilder » Close form from OnShow (BCB3)

Close form from OnShow (BCB3)

I'm trying to close window from its OnShow event, but no success.
The form is modal and setting its ModalResult to some value or calling
Close() method doesnt close it. Any ideas?
 

Re:Close form from OnShow (BCB3)


Quote
RedOne wrote:

> I'm trying to close window from its OnShow event, but no success.
> The form is modal and setting its ModalResult to some value or calling
> Close() method doesnt close it. Any ideas?

The trouble with what you're doing is that after the OnShow event
returns the form initialises the ModalResult property thus defeating
your attempts to close the form. What I have done in the past is to send
a WM_CLOSE message to the form using PostMessage. It will get processed
after the form has completed all it's initialising, but you may get an
irritating "flash" on the screen.

Perhaps you could experiment moving the PostMessage to the OnActivate
method to eliminate the flash.

Other Threads