Пример #1
0
        public static void MaybePersist(Form form)
        {
            PersistentWindowAttribute pwa = GetAttrib(form);

            if (pwa == null)
            {
                return;
            }

            SaveWindowBounds(pwa.WindowKey, form.Bounds);
        }
        /// <summary>
        /// Handle OnLoad -- set standard icon
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!DesignMode)
            {
                PersistentWindowAttribute.MaybeRestore(this);
            }
            Form owner = this.Owner;

            if (owner != null)
            {
                this.TopMost = owner.TopMost;
            }
        }
        protected override void OnClosed(EventArgs e)
        {
            if (!DesignMode)
            {
                try
                {
                    PersistentWindowAttribute.MaybePersist(this);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Exception trying to persist form settings on " + this.GetType().FullName + ": " + ex.ToString());
                }
            }

            base.OnClosed(e);
        }
Пример #4
0
        public static void MaybeRestore(Form form)
        {
            PersistentWindowAttribute pwa = GetAttrib(form);

            if (pwa == null)
            {
                return;
            }

            Rectangle bounds = LoadWindowBounds(pwa.WindowKey, form.Bounds);

            if (pwa.Size && pwa.Location)
            {
                form.Bounds = bounds;
            }
            else if (pwa.Size)
            {
                form.Size = bounds.Size;
            }
            else if (pwa.Location)
            {
                form.Location = bounds.Location;
            }
        }