Solved

Adding two tags to Menuitems with ExtenderProvider

Posted on 2004-08-31
5
505 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
vb.net convert long time to mm:ss 23 34
vb.net datagrid point 4 35
Updating Printer Details in VB.Net 16 43
VB.NET Parsing UDP Bytes 15 37
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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