private int HandleButtonClick(int id) { // First we raise a Click event, if there is a custom button // However, we implement Close() by sending a cancel button, so we // don't want to raise a click event in response to that if (showState != NativeDialogShowState.Closing) { outerDialog.RaiseButtonClickEvent(id); } // Once that returns, we raise a Closing event for the dialog // The Win32 API handles button clicking-and-closing as an atomic action, // but it is more .NET friendly to split them up. // Unfortunately, we do NOT have the return values at this stage ... return(outerDialog.RaiseClosingEvent(id)); }