1) How can I make it so that when the user clicks the red X at the top-right corner of the window, the level editor asks the user if they are sure they want to exit without saving? I have the following code, but it doesn't work. It closes the level editor before showing the dialog box.
protected override void OnExiting(object sender, EventArgs args)
{
if (GUI.HUD.saved)
{
base.OnExiting(sender, args);
}
else // map is not saved
{
bool result = warnMapNotSaved();
if (result == true)
{
base.OnExiting(sender, args);
}
else
{
}
}
}
private bool warnMapNotSaved()
{
state = State.FREEZE;
DialogResult result = System.Windows.Forms.MessageBox.Show("There are unsaved changes to the map. Are you sure you wish to exit?", "Map Not Saved", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
return true;
}
else
{
state = State.PLAY;
return false;
}
}
I have also tried overriding the EndRun() method, but it ends with the same result.
2) How can I only accept letters (A-Z, a-z), numbers (0-9), and spaces in a text box in a Windows Form? It's a place where users can type in a map name (not file name), but I don't want them typing in bad names that could be hard to deal with in code (such as \r\n).