ComponentOne Menus and Toolbars for WinForms
C1.Win.C1Command.4.5.2 Assembly / C1.Win.C1Command Namespace / C1ContextMenu Class / SourceControl Property
Example

In This Topic
    SourceControl Property (C1ContextMenu)
    In This Topic
    Gets the control that is displaying the shortcut menu.
    Syntax
    'Declaration
     
    Public ReadOnly Property SourceControl As System.Windows.Forms.Control
    public System.Windows.Forms.Control SourceControl {get;}
    Remarks
    This property enables you to determine which control currently displays the shortcut menu defined in the C1ContextMenu. If the shortcut menu is not currently displayed, you can use this property to determine which control last displayed the shortcut menu. You can use this property in the C1CommandMenu.Popup event to ensure that the control displays the proper menu items. You can also use this property to pass a reference to the control to a method that performs the tasks associated with a menu command displayed in the shortcut menu.
    Example

    The following code example creates an event handler for the C1CommandMenu.Popup event of the C1ContextMenu. The code in the event handler determines which of two controls a PictureBox named pictureBox1 and a TextBox named textBox1 is the control displaying the shortcut menu.

    Depending on which control caused the C1ContextMenu to display its shortcut menu, the control shows or hides the appropriate menu items of C1Command.

    This example requires that you have an instance of the C1ContextMenu class, named c1ContextMenu1, defined within the form. c1ContextMenu should have "Copy", "Find", "Change Picture" menu items. This example also requires that you have a TextBox and PictureBox added to a form and that the C1ContextMenu property of these controls is set to c1ContextMenu1.

    private void c1ContextMenu1_Popup(object sender, EventArgs e)
    {
        Control c = c1ContextMenu1.SourceControl;
        // Copy and Find is dispayed for textBox1
        c1CommandCopy.Visible = (c == textBox1);
        c1CommandFind.Visible = (c == textBox1);
        // Change Picture is dispayed for pictureBox1
        c1CommandChangePicture.Visible = (c == pictureBox1);
    }
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also