using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; namespace Sheng.Winform.Controls.PopupControl { /// /// Represents a Windows combo box control which can be used in a popup's content control. /// [ToolboxBitmap(typeof(System.Windows.Forms.ComboBox)), ToolboxItem(true), ToolboxItemFilter("System.Windows.Forms"), Description("Displays an editable text box with a drop-down list of permitted values.")] public partial class PopupControlComboBoxBase : System.Windows.Forms.ComboBox { /// /// Initializes a new instance of the PopupControl.ComboBox class. /// public PopupControlComboBoxBase() { InitializeComponent(); } private static Type _modalMenuFilter; private static Type ModalMenuFilter { get { if (_modalMenuFilter == null) { _modalMenuFilter = Type.GetType("System.Windows.Forms.ToolStripManager+ModalMenuFilter"); } if (_modalMenuFilter == null) { _modalMenuFilter = new List(typeof(ToolStripManager).Assembly.GetTypes()).Find( delegate(Type type) { return type.FullName == "System.Windows.Forms.ToolStripManager+ModalMenuFilter"; }); } return _modalMenuFilter; } } private static MethodInfo _suspendMenuMode; private static MethodInfo SuspendMenuMode { get { if (_suspendMenuMode == null) { Type t = ModalMenuFilter; if (t != null) { _suspendMenuMode = t.GetMethod("SuspendMenuMode", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } } return _suspendMenuMode; } } private static void VSuspendMenuMode() { MethodInfo suspendMenuMode = PopupControlComboBoxBase.SuspendMenuMode; if (suspendMenuMode != null) { suspendMenuMode.Invoke(null, null); } } private static MethodInfo _resumeMenuMode; private static MethodInfo ResumeMenuMode { get { if (_resumeMenuMode == null) { Type t = ModalMenuFilter; if (t != null) { _resumeMenuMode = t.GetMethod("ResumeMenuMode", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } } return _resumeMenuMode; } } private static void VResumeMenuMode() { MethodInfo resumeMenuMode = PopupControlComboBoxBase.ResumeMenuMode; if (resumeMenuMode != null) { resumeMenuMode.Invoke(null, null); } } /// /// Raises the event. /// /// An that contains the event data. protected override void OnDropDown(EventArgs e) { base.OnDropDown(e); VSuspendMenuMode(); } /// /// Raises the event. /// /// An that contains the event data. protected override void OnDropDownClosed(EventArgs e) { VResumeMenuMode(); base.OnDropDownClosed(e); } } }