Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding two tags to Menuitems with ExtenderProvider

Posted on 2004-08-31
5
Medium Priority
?
530 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
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

877 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