Solved

Adding two tags to Menuitems with ExtenderProvider

Posted on 2004-08-31
5
518 Views
Last Modified: 2008-01-09
The following code, found on the net, adds a tag to each MenuItem. Works well. But...I want to add ANOTHER tag, call it Tag2. How?
--------


Imports System.ComponentModel
Imports System.Windows.Forms

<ProvideProperty("Tag", GetType(MenuItem))> _
Public Class MenuTagger
    Inherits Component
    Implements IExtenderProvider

#Region "Extender Implementation "

    Private Props As Hashtable = New Hashtable()

    Public Function CanExtend(ByVal Ctl As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf Ctl Is MenuItem Then Return True
    End Function

    <ExtenderProvidedProperty(), Category("Appearance"), DefaultValue(GetType(String), Nothing)> _
    Public Function GetTag(ByVal target As MenuItem) As String
        If Props.Contains(target) Then
            Return CType(Props(target), String)
        End If
        Props.Add(target, Nothing)
    End Function

    Public Sub SetTag(ByVal target As MenuItem, ByVal value As String)
        If Props.Contains(target) Then
            Props.Remove(target)
        End If
        Props.Add(target, value)
    End Sub

#End Region

End Class
0
Comment
Question by:rdavis101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 125 total points
ID: 11951358
Can't you simply do this

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Windows.Forms

<ProvideProperty("Tag", GetType(MenuItem))> _
Public Class MenuTagger
    Inherits Component
    Implements IExtenderProvider

#Region "Extender Implementation "

    Private Props As Hashtable = New Hashtable
    Private Props2 As Hashtable = New Hashtable

    Public Function CanExtend(ByVal Ctl As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf Ctl Is MenuItem Then Return True
    End Function

    <ExtenderProvidedProperty(), Category("Appearance"), DefaultValue(GetType(String), Nothing)> _
    Public Function GetTag(ByVal target As MenuItem) As String
        If Props.Contains(target) Then
            Return CType(Props(target), String)
        End If
        Props.Add(target, Nothing)
    End Function

    Public Sub SetTag(ByVal target As MenuItem, ByVal value As String)
        If Props.Contains(target) Then
            Props.Remove(target)
        End If
        Props.Add(target, value)
    End Sub

    Public Function GetTag2(ByVal target As MenuItem) As String
        If Props2.Contains(target) Then
            Return CType(Props2(target), String)
        End If
        Props2.Add(target, Nothing)
    End Function

    Public Sub SetTag2(ByVal target As MenuItem, ByVal value As String)
        If Props2.Contains(target) Then
            Props2.Remove(target)
        End If
        Props2.Add(target, value)
    End Sub

#End Region
0
 

Author Comment

by:rdavis101
ID: 11951963
Did you test this?  I'm in the process of testing it now.

Question: WHy does the line

<ProvideProperty("Tag", GetType(MenuItem))> _

Appear only once?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11952178
Yes I did and it worked. The provideproperty and ExtenderProvidedProperty are things you will see in the property window if you decide to create your own "mainmenu" control
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11952197
look here for a better explaination

http://www.devx.com/dotnet/Article/21462/1763/page/2
0
 

Author Comment

by:rdavis101
ID: 11952469
Dude, thanks so much! :)

Roger
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question