Results 1 to 9 of 9

Thread: [RESOLVED] How can I add a link (like TreeView control has) into a usercontrol?

  1. #1

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

    Resolved [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!!!

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

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

    Re: How can I add a link (like TreeView control has) into a usercontrol?

    Quote Originally Posted by techgnome View Post
    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!!!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    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.

  6. #6

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

    Re: How can I add a link (like TreeView control has) into a usercontrol?

    Quote Originally Posted by jmcilhinney View Post
    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.

    Quote Originally Posted by Sitten Spynne View Post
    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!!!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

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

    Re: How can I add a link (like TreeView control has) into a usercontrol?

    Quote Originally Posted by jmcilhinney View Post
    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...

  9. #9

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

    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.
    Attached Images Attached Images   

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