|
-
Apr 2nd, 2018, 07:27 AM
#1
Thread Starter
Lively Member
[RESOLVED] How can I add a link (like TreeView control has) into a usercontrol?
I am working on a UserControl and I want to place something like this link label (?) which we can see under TreeView control in Properties Window.

I don't want it to open an editor window, like in TreeView control does. I want to add my own action. The question is, how can I place a link like this on my UserControl? Is it possible?
Thank you in advance!!!
-
Apr 2nd, 2018, 07:30 AM
#2
Re: How can I add a link (like TreeView control has) into a usercontrol?
It's not clear if you want it at design time in the properties window, or on the user control itself. If you want it on the user control itself then a LinkLabel is the way to go. If you mean at design time in the properties window.... I'm not sure.
-tg
-
Apr 2nd, 2018, 07:50 AM
#3
Thread Starter
Lively Member
Re: How can I add a link (like TreeView control has) into a usercontrol?
 Originally Posted by techgnome
It's not clear if you want it at design time in the properties window, or on the user control itself. If you want it on the user control itself then a LinkLabel is the way to go. If you mean at design time in the properties window.... I'm not sure.
-tg
Yes, sorry I didn't mention it, I want it at design time in the properties window!!!
-
Apr 2nd, 2018, 09:20 AM
#4
Re: How can I add a link (like TreeView control has) into a usercontrol?
I've done very little when it comes to custom controls so I don't know a lot on this subject but I think that this might be a good place to start:
https://www.codeproject.com/articles...rtygrid-comman
-
Apr 2nd, 2018, 10:56 AM
#5
Re: How can I add a link (like TreeView control has) into a usercontrol?
JMC's link is a good reference, these are called "Designer Verbs" in UI designer parlance and it takes a bit of dancing to set them up, but once you've done it the first time it's easier the next.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Apr 2nd, 2018, 11:29 AM
#6
Thread Starter
Lively Member
Re: How can I add a link (like TreeView control has) into a usercontrol?
 Originally Posted by jmcilhinney
I've done very little when it comes to custom controls so I don't know a lot on this subject but I think that this might be a good place to start...
Thanks for the link!!! Of course I have to study it first and manage to understand what is happening "in there" lol.
 Originally Posted by Sitten Spynne
JMC's link is a good reference, these are called "Designer Verbs" in UI designer parlance and it takes a bit of dancing to set them up, but once you've done it the first time it's easier the next.
"Designer Verbs"... Nice, now I know how to search for more informations about it!!! Thank you very much!!!
-
Apr 2nd, 2018, 07:52 PM
#7
Re: How can I add a link (like TreeView control has) into a usercontrol?
For the record, the way I found that link was to read the documentation for the PropertyGrid control, which is the same control that is used in the Properties window of the WinForms designer, to see what it said about that area. From that I got the term "command pane" and then I just did a web search for "propertygrid command pane".
Last edited by jmcilhinney; Apr 3rd, 2018 at 04:05 AM.
Reason: Added missing word.
-
Apr 3rd, 2018, 03:52 AM
#8
Thread Starter
Lively Member
Re: How can I add a link (like TreeView control has) into a usercontrol?
 Originally Posted by jmcilhinney
For the record, the way I found that link was to read the documentation for the PropertyGrid control, which is the same control that is used in the Properties window of the WinForms designer, to see what it said about area. From that I got the term "command pane" and then I just did a web search for "propertygrid command pane".
Very useful note, mostly for people like me, who sometimes don't know how to search things because of poor terminology knowledge...
-
Apr 4th, 2018, 08:06 AM
#9
Thread Starter
Lively Member
Re: How can I add a link (like TreeView control has) into a usercontrol?
Well, here is a simple example...
1. If we haven't done already, we should first add a reference to System.Design. Goto Reference Manager > Assemblies > Framework and find System.Design. Check it and click OK.
2. Into our UserControl code, we make sure that we already have Imports System.ComponentModel and Imports System.ComponentModel.Design references.
3. Over our UserControl class, we add a Designer attribute, to specify our ControlDesigner for this UserControl.
Code:
Imports System.ComponentModel
Imports System.ComponentModel.Design
<Designer(GetType(MyControlDesigner))>
Public Class UserControl1
'Our UserControl code in here...
End Class
4. Under our UserControl class, we create a new class by the name "MyControlDesigner" which will be our ControlDesigner.
Code:
Public Class MyControlDesigner
End Class
5. Now, for example, lets create a Verb which will Dock and Undock our UserControl in ParentForm.
Code:
Public Class MyControlDesigner
Inherits System.Windows.Forms.Design.ControlDesigner 'Inherit from ControlDesigner class.
Private MyVerbs As DesignerVerbCollection
Public Sub New()
End Sub
Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
Get
If MyVerbs Is Nothing Then
MyVerbs = New DesignerVerbCollection 'A new DesignerVerbCollection to use for our DesignerVerbs.
MyVerbs.Add(New DesignerVerb("Dock In ParentForm", New EventHandler(AddressOf OnMyCommandLinkClicked))) 'An Event Handler for Docking our UserControl.
MyVerbs.Add(New DesignerVerb("Undock in ParentForm", New EventHandler(AddressOf OnMyCommandLinkClicked))) 'An Event Handler for Undocking our UserControl.
MyVerbs(1).Visible = False 'We hide second Verd by default.
End If
Return MyVerbs
End Get
End Property
Private Sub OnMyCommandLinkClicked(ByVal sender As Object, ByVal args As EventArgs)
Dim _UserControl As UserControl1 = CType(Me.Control, UserControl1) 'Reference to our UserControl1 Class, so we can access it's Properties and Methods.
If _UserControl.Dock = DockStyle.None Then 'If UserControl is Undocked then...
_UserControl.Dock = DockStyle.Fill 'Dock UserControl in ParentForm.
MyVerbs(0).Visible = False 'Hide "Dock In ParentForm" DesignerVerb.
MyVerbs(1).Visible = True 'Show "Undock in ParentForm" DesignerVerb.
Else
_UserControl.Dock = DockStyle.None 'Undock UserControl.
MyVerbs(1).Visible = False 'Hide "Undock in ParentForm" DesignerVerb.
MyVerbs(0).Visible = True 'Show "Dock in ParentForm" DesignerVerb.
End If
End Sub
End Class
6. Then we Build our project and we add our UserControl into our test Form.
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
|