Export (0) Print
Expand All

DesignerVerb Class

Represents a verb that can be invoked from a designer.

For a list of all members of this type, see DesignerVerb Members.

System.Object
   System.ComponentModel.Design.MenuCommand
      System.ComponentModel.Design.DesignerVerb
         System.Web.UI.Design.TemplateEditingVerb

[Visual Basic]
<ComVisible(True)>
Public Class DesignerVerb
   Inherits MenuCommand
[C#]
[ComVisible(true)]
public class DesignerVerb : MenuCommand
[C++]
[ComVisible(true)]
public __gc class DesignerVerb : public MenuCommand
[JScript]
public
   ComVisible(true)
class DesignerVerb extends MenuCommand

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

A designer verb is a menu command linked to an event handler. Designer verbs are added to a component's context menu and the Properties window at run time.

Example

[Visual Basic, C#, C++] The following example demonstrates how to create DesignerVerb objects and add them to the design-time context menu for a component.

[Visual Basic] 
Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.ComponentModel.Design

'  This sample demonstrates a designer that adds menu commands
'   to the design-time context menu for a component.
'
'   To test this sample, build the code for the component as a class library, 
'   add the resulting component to the toolbox, open a form in design mode, 
'   and drag the component from the toolbox onto the form. 
'
'   The component should appear in the component tray beneath the form. 
'   Right-click the component.  The verbs should appear in the context menu.

Namespace VBDesignerVerb
    ' Associate MyDesigner with this component type using a DesignerAttribute
    <Designer(GetType(MyDesigner))> _
    Public Class Component1
        Inherits System.ComponentModel.Component
    End Class 'Component1


    '  This is a designer class which provides designer verb menu commands for 
    '  the associated component. This code is called by the design environment at design-time.    
    Friend Class MyDesigner
        Inherits ComponentDesigner

        Private m_Verbs As DesignerVerbCollection

        ' DesignerVerbCollection is overridden from ComponentDesigner
        Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
            Get
                If m_Verbs Is Nothing Then
                    ' Create and initialize the collection of verbs
                    m_Verbs = New DesignerVerbCollection()
            m_Verbs.Add( New DesignerVerb("First Designer Verb", New EventHandler(AddressOf OnFirstItemSelected)) )
            m_Verbs.Add( New DesignerVerb("Second Designer Verb", New EventHandler(AddressOf OnSecondItemSelected)) )
                End If
                Return m_Verbs
            End Get
        End Property

        Sub New()
        End Sub 'New

        Private Sub OnFirstItemSelected(ByVal sender As Object, ByVal args As EventArgs)
            ' Display a message
            System.Windows.Forms.MessageBox.Show("The first designer verb was invoked.")
        End Sub 'OnFirstItemSelected

        Private Sub OnSecondItemSelected(ByVal sender As Object, ByVal args As EventArgs)
            ' Display a message
            System.Windows.Forms.MessageBox.Show("The second designer verb was invoked.")
        End Sub 'OnSecondItemSelected
    End Class 'MyDesigner
End Namespace

[C#] 
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;

/* This sample demonstrates a designer that adds menu commands
    to the design-time context menu for a component.

    To test this sample, build the code for the component as a class library, 
    add the resulting component to the toolbox, open a form in design mode, 
    and drag the component from the toolbox onto the form. 

    The component should appear in the component tray beneath the form. 
    Right-click the component.  The verbs should appear in the context menu.
*/

namespace CSDesignerVerb
{
    // Associate MyDesigner with this component type using a DesignerAttribute
    [Designer(typeof(MyDesigner))]
    public class Component1 : System.ComponentModel.Component
    {
    }

    // This is a designer class which provides designer verb menu commands for 
    // the associated component. This code is called by the design environment at design-time.
    internal class MyDesigner : ComponentDesigner
    {
        DesignerVerbCollection m_Verbs;

        // DesignerVerbCollection is overridden from ComponentDesigner
        public override DesignerVerbCollection Verbs
        {
            get {
                if (m_Verbs == null) 
                {
                    // Create and initialize the collection of verbs
                    m_Verbs = new DesignerVerbCollection();
            
            m_Verbs.Add( new DesignerVerb("First Designer Verb", new EventHandler(OnFirstItemSelected)) );
            m_Verbs.Add( new DesignerVerb("Second Designer Verb", new EventHandler(OnSecondItemSelected)) );
                }
                return m_Verbs;
            }
        }

        MyDesigner() 
        {
        }

        private void OnFirstItemSelected(object sender, EventArgs args) 
        {
            // Display a message
            System.Windows.Forms.MessageBox.Show("The first designer verb was invoked.");
        }

        private void OnSecondItemSelected(object sender, EventArgs args) 
        {
            // Display a message
            System.Windows.Forms.MessageBox.Show("The second designer verb was invoked.");
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>
#using <system.design.dll>
#using <system.windows.forms.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Windows::Forms;

/* This sample demonstrates a designer that adds menu commands
to the design-time context menu for a component.

To test this sample, build the code for the component as a class library,
add the resulting component to the toolbox, open a form in design mode,
and drag the component from the toolbox onto the form.

The component should appear in the component tray beneath the form.
Right-click the component.  The verbs should appear in the context menu.
*/

namespace CSDesignerVerb
{
    // This is a designer class which provides designer verb menu commands for
    // the associated component. This code is called by the design environment at design-time.
    private __gc class MyDesigner : public ComponentDesigner {
    public:

        // DesignerVerbCollection is overridden from ComponentDesigner
        __property DesignerVerbCollection* get_Verbs()
        {
            if (m_Verbs == 0)
            {
                // Create and initialize the collection of verbs
                m_Verbs = new DesignerVerbCollection();

                m_Verbs->Add( new DesignerVerb(S"First Designer Verb",
                    new EventHandler(this, &MyDesigner::OnFirstItemSelected)) );
                m_Verbs->Add( new DesignerVerb(S"Second Designer Verb",
                    new EventHandler(this, &MyDesigner::OnSecondItemSelected)) );
            }

            return m_Verbs;
        }

        MyDesigner()
        {
        }

    private:

        DesignerVerbCollection* m_Verbs;

        void OnFirstItemSelected(Object* /*sender*/, EventArgs* /*args*/)
        {
            // Display a message
            MessageBox::Show(S"The first designer verb was invoked.");
        }

        void OnSecondItemSelected(Object* /*sender*/, EventArgs* /*args*/)
        {
            // Display a message
            MessageBox::Show(S"The second designer verb was invoked.");
        }
    };

    // Associate MyDesigner with this component type using a DesignerAttribute
    [Designer(__typeof(MyDesigner))]
    public __gc class Component1 : public System::ComponentModel::Component
    {
    };

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

DesignerVerb Members | System.ComponentModel.Design Namespace | MenuCommand | IMenuCommandService

Show:
© 2014 Microsoft