If you need to differentiate between closing with cancel and closing with confirm, then your need two separate buttons
Button cancellation = new Button()
{ Text = "Cancel", Left = prompt.Width / 2 + 10, Width = 50, Top = 50 };
prompt.CancelButton = cancellation;
cancellation.DialogResult = DialogResult.Cancel;
also your confirmation button needs the setting for DialogResult property
confirmation.DialogResult = DialogResult.OK;
so you could get the result of the ShowDialog with
if(DialogResult.OK == prompt.ShowDialog())
{
int num;
Int32.TryParse(value.Text, out num);
return num;
}
else
return 0; // Or whatever to signal failure
By the way, setting the DialogResult property to something different that DialogResult.None will result in the form closing by itself without any need of a click event to close the form.