| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | using System;using System.Windows.Forms;namespace PaintDotNet.SystemLayer{    /// <summary>    /// This class adds on to the functionality provided in System.Windows.Forms.MenuStrip.    /// </summary>    public class MenuStripEx        : MenuStrip    {        private bool clickThrough = true;        private static int openCount = 0;        public MenuStripEx()        {            this.ImageScalingSize = new System.Drawing.Size(UI.ScaleWidth(16), UI.ScaleHeight(16));        }        /// <summary>        /// Gets or sets whether the ToolStripEx honors item clicks when its containing form does        /// not have input focus.        /// </summary>        /// <remarks>        /// Default value is true, which is the opposite of the behavior provided by the base        /// ToolStrip class.        /// </remarks>        public bool ClickThrough        {            get            {                return this.clickThrough;            }            set            {                this.clickThrough = value;            }        }        protected override void WndProc(ref Message m)        {            base.WndProc(ref m);            if (this.clickThrough)            {                UI.ClickThroughWndProc(ref m);            }        }        /// <summary>        /// Gets a value indicating whether any menu is currently open.        /// </summary>        /// <remarks>        /// To be precise, this will return true if any menu has raised its MenuActivate event        /// but has yet to raise its MenuDeactivate event.</remarks>        public static bool IsAnyMenuActive        {            get            {                return openCount > 0;            }        }        public static void PushMenuActivate()        {            ++openCount;        }        public static void PopMenuActivate()        {            --openCount;        }        protected override void OnMenuActivate(EventArgs e)        {            ++openCount;            base.OnMenuActivate(e);        }        protected override void OnMenuDeactivate(EventArgs e)        {            --openCount;            base.OnMenuDeactivate(e);        }    }}
 |