Solved

Adding two tags to Menuitems with ExtenderProvider

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now