-
May 27th, 2018, 06:02 AM
#1
Thread Starter
Lively Member
[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:
<Designer(GetType(CustomDesigner))> Public Class CustomForm Inherits Form '... End Class
I have also try to do all the "work" into my custom form's class like this...
vb.net Code:
Imports System.ComponentModel.Design Public Class CustomForm Inherits Form '... Private _Verbs As DesignerVerbCollection Public ReadOnly Property Verbs() As DesignerVerbCollection Get 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
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.
-
May 27th, 2018, 07:04 AM
#2
Thread Starter
Lively Member
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:
Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
MyBase.OnHandleCreated(e)
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|