Here’s how I handled it. In its own function I stored the dialog result from message box. The OK result returned false and Cancel returned true. It returned to the ToolClick function, where, if the result was true, then args.handled = true. Setting args.handled to true cancelled the proceeding actions. To reset the form to how it was before clicking save, I called oTrans.Refresh();
private bool DisplayOKCancelMessage()
{
if ((System.Decimal)materialCost.Value != 0 ||
(System.Decimal)burdenCost.Value != 0 ||
(System.Decimal)subcontractCost.Value != 0 ||
(System.Decimal)materialBurdenCost.Value != 0 ||
(System.Decimal)laborCost.Value != 0)
{
DialogResult dialogResult = MessageBox.Show("Please make sure all cost fields are set to $0 before receiving this RMA. Continue?", "Warning",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
if (dialogResult == DialogResult.OK)
{
// Do nothing and let the form save
return false;
}
else if (dialogResult == DialogResult.Cancel)
{
// Cancel the save action
return true;
}
}
return false;
}
private void baseToolbarsManager_ToolClick(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
{
if (args.Tool.Key == "SaveTool")
if (DisplayOKCancelMessage())
args.Handled = true;
}