示例#1
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.</summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _gifAnim = new GifAnimator(SynchronizationContext.Current);
            _gallery = new ImageGallery(Font, DeviceDpi, _gifAnim);

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                // Load our image data.
                _gallery.LoadImages(GorgonApplication.StartupPath.FullName);


                // Begin our animation.
                _gifAnim.Animate(() =>
                {
                    using (System.Drawing.Graphics graphics = CreateGraphics())
                    {
                        _gallery.RefreshGif(graphics);
                    }
                });
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
                GorgonApplication.Quit();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
示例#2
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data. </param>
        protected override async void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (_gifAnim == null)
            {
                return;
            }

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                // Cancel form closure because we need to wait until the thread is done prior to moving on.
                e.Cancel = true;
                try
                {
                    await _gifAnim.CancelAsync();
                }
                catch (OperationCanceledException)
                {
                    // Do nothing, this could happen in Task.Delay.
                }

                e.Cancel = false;

                _gallery.Dispose();
                _gifAnim = null;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
            Close();
        }