Click here to Skip to main content
15,667,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is it possible to add DesignerVerbs on a custom form class? I have try to make a custom designer class for my custom form class and use it like this [1]. I have also try to do all the "work" into my custom form's class like this [2]. But with no luck. Any idea how can I do that? If it is possible...

What I have tried:

    Public Class CustomForm
        Inherits Form
    End Class

Imports System.ComponentModel.Design
    Public Class CustomForm
        Inherits Form
        Private _Verbs As DesignerVerbCollection
        Public ReadOnly Property Verbs() As DesignerVerbCollection
                If _Verbs Is Nothing Then
                    _Verbs = New DesignerVerbCollection From {
                    New DesignerVerb("Verb1", New EventHandler(AddressOf EventHandler1)),
                    New DesignerVerb("Verb2", New EventHandler(AddressOf EventHandler2))
                    _Verbs(0).Visible = False
                    _Verbs(1).Visible = True
                End If
                Return _Verbs
            End Get
        End Property
        Private Sub EventHandler1(ByVal sender As Object, ByVal e As EventArgs)
        End Sub
        Private Sub EventHandler2(ByVal sender As Object, ByVal e As EventArgs)
        End Sub
    End Class
Updated 27-May-18 2:35am

1 solution

I got an easy solution on my question here at
Reza Aghaei: If you are going to add some custom verbs to designer of a Form, you need to create a new custom Designer by deriving from DocumentDesigner and overriding a lot of properties and method to recreate FormDesigner. As an easier solution, you can tweak designer of base form of your form. Let's say, you have Form1 and you want to have Do Something verb for it. To do so, if BaseForm is the base form for your Form1, it's enough to add the following code to BaseForm:
Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
	Dim host = DirectCast(Me.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
	Dim designer = host.GetDesigner(Me)
	designer.Verbs.Add(New DesignerVerb("Do Something", Sub(obj, args)
		MessageBox.Show("Something done!")
	End Sub))
End Sub
As a result, Do Something will be added to context menu for your Form1:
Share this answer
Ralf Meier 27-May-18 15:13pm    
Thanks for posting the result from your research also in this Forum. +5 from me for this.
Also the content from this answer is useful for me too ...
Simos Sigma 27-May-18 15:41pm    
You are welcome my friend!!! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900