System.Windows.Forms.ContextMenu.OnPopup C# (CSharp) Method

OnPopup() protected method

protected OnPopup ( EventArgs e ) : void
e System.EventArgs
return void
		protected internal virtual void OnPopup (EventArgs e)
		{
			EventHandler eh = (EventHandler) (Events [PopupEvent]);
			if (eh != null)
				eh (this, e);
		}
		

Usage Example

Example #1
0
        public void ContextMenu_OnPopup_Invoke_Success()
        {
            var menu = new ContextMenu();

            // No handler.
            menu.OnPopup(null);

            // Handler.
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Equal(menu, sender);
                callCount++;
            };

            menu.Popup += handler;
            menu.OnPopup(null);
            Assert.Equal(1, callCount);

            // Should not call if the handler is removed.
            menu.Popup -= handler;
            menu.OnPopup(null);
            Assert.Equal(1, callCount);
        }