public MainForm() { InitializeComponent(); m_popedContainerForButton = new ContextMenuForButton(); m_poperContainerForButton = new PoperContainer(m_popedContainerForButton); m_popedContainerForForm = new ContextMenuForForm(); m_poperContainerForForm = new PoperContainer(m_popedContainerForForm); m_popedContainerForLabel = new ContextMenuForLabel(); m_poperContainerForLabel = new PoperContainer(m_popedContainerForLabel); // add the event handlers here for the changes to take effects................................... // NOTE: members must be public m_popedContainerForButton.buttonCut.Click += new System.EventHandler(this.buttonCut_Click); m_popedContainerForButton.buttonCopy.Click += new System.EventHandler(this.buttonCopy_Click); m_popedContainerForButton.buttonPaste.Click += new System.EventHandler(this.buttonPaste_Click); m_popedContainerForButton.comboBoxBorder.SelectedIndexChanged += new System.EventHandler(this.comboBoxBorder_SelectedIndexChanged); m_popedContainerForButton.textBoxCaption.TextChanged += new EventHandler(textBoxCaption_TextChanged); m_popedContainerForButton.buttonColor.Click += new System.EventHandler(this.buttonColor_Click); m_popedContainerForForm.textBoxCaption.TextChanged += new EventHandler(this.ChangeFormTitle); m_popedContainerForForm.buttonColor.Click += new System.EventHandler(this.ChangeFormBKColor); m_popedContainerForLabel.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll); }
public PoperContainer() { InitializeComponent(); if (contextMenu == null) { throw new ArgumentNullException("content"); } this.m_popedContainer = contextMenu; this.m_fade = SystemInformation.IsMenuAnimationEnabled && SystemInformation.IsMenuFadeEnabled; this.m_host = new ToolStripControlHost(contextMenu); m_host.AutoSize = false;//make it take the same room as the poped control Padding = Margin = m_host.Padding = m_host.Margin = Padding.Empty; contextMenu.Location = Point.Empty; this.Items.Add(m_host); contextMenu.Disposed += delegate(object sender, EventArgs e) { contextMenu = null; Dispose(true);// this popup container will be disposed immediately after disposion of the contained control }; }