/// <summary> /// Handles the FormClosing event of the AnimationForm control. /// Checks if collision shapes are valid and animation has at least one frame. If not form is not closed until all shapes and animation are valid. /// If yes, saves data to the animation and invokes its <see cref="DrawableAsset.DrawableAssetChanged"/>. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.FormClosingEventArgs"/> instance containing the event data.</param> private void AnimationForm_FormClosing(object sender, FormClosingEventArgs e) { // check if every shape is valid for (int i = 0; i < shapesController.ShapesList.Items.Count; ++i) { ShapeState shapeState = shapesController.ShapesList.Items[i] as ShapeState; if (shapeState != null) { // shape is not valid if (!shapeState.IsShapeValid()) { // select invalid shape shapesController.ShapesList.SelectedIndex = i; // show message shapeState.OnInvalidShape(); // form will not be closed until all shapes are valid e.Cancel = true; return; } } } // check if animation is valid if (framesView.Items.Count == 0) { // show message Messages.ShowWarning("Invalid animation. No frame is set."); // form will not be closed until all shapes are valid e.Cancel = true; return; } // animation is valid => update animation UpdateAnimation(); // animation changed animation.InvokeDrawableAssetChanged(); }