Results 1 to 2 of 2

Thread: [RESOLVED] Is it possible to add DesignerVerbs on a custom Form?

  1. #1

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    Resolved [RESOLVED] Is it possible to add DesignerVerbs on a custom Form?



    Is it possible to add DesignerVerbs on a custom form? I have try to make a custom designer class for my custom form class and use it like this...

    vb.net Code:
    1. <Designer(GetType(CustomDesigner))>
    2.     Public Class CustomForm
    3.         Inherits Form
    4.         '...
    5.     End Class
    I have also try to do all the "work" into my custom form's class like this...

    vb.net Code:
    1. Imports System.ComponentModel.Design
    2.    
    3.     Public Class CustomForm
    4.         Inherits Form
    5.         '...
    6.         Private _Verbs As DesignerVerbCollection
    7.         Public ReadOnly Property Verbs() As DesignerVerbCollection
    8.             Get
    9.                 If _Verbs Is Nothing Then
    10.                     _Verbs = New DesignerVerbCollection From {
    11.                     New DesignerVerb("Verb1", New EventHandler(AddressOf EventHandler1)),
    12.                     New DesignerVerb("Verb2", New EventHandler(AddressOf EventHandler2))
    13.                     }
    14.                     _Verbs(0).Visible = False
    15.                     _Verbs(1).Visible = True
    16.                 End If
    17.                 Return _Verbs
    18.             End Get
    19.         End Property
    20.         Private Sub EventHandler1(ByVal sender As Object, ByVal e As EventArgs)
    21.             '...
    22.         End Sub
    23.         Private Sub EventHandler2(ByVal sender As Object, ByVal e As EventArgs)
    24.             '...
    25.         End Sub
    26.     End Class
    But with no luck. Any idea how can I do that? If it is possible...
    Last edited by Simonetos The Greek; May 27th, 2018 at 06:29 AM.

  2. #2

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    Re: Is it possible to add DesignerVerbs on a custom Form?

    I got an easy solution on my question here at stackoverflow.com.

    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:
    vb.net Code:
    1. Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
    2.     MyBase.OnHandleCreated(e)
    3.     Dim host = DirectCast(Me.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
    4.     Dim designer = host.GetDesigner(Me)
    5.     designer.Verbs.Add(New DesignerVerb("Do Something", Sub(obj, args)
    6.         MessageBox.Show("Something done!")
    7.     End Sub))
    8. End Sub
    As a result, Do Something will be added to context menu for your Form1:

    Name:  j2L12.png
Views: 114
Size:  14.4 KB

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width