The thing you need is an object that implements IExtenderProvider.
An extender-provider can "extend" other object by appearing to add
properties to them at design time. Note that at runtime the process is
handled differently.
The object being extended has no knowlege of the new properties either.
After my signature you'll find a simple extender-provider that adds "status"
properties to menu items. These properties can be displayed in a status bar
chosen at design time.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Drawing
Imports System.Windows.Forms
<ToolboxItem(True), _
ToolboxBitmap(GetType(MenuStatusExtender), "MenuStatusExtender.bmp"), _
ProvideProperty("StatusText", "System.Windows.Forms.MenuItem") _
_
Public Class MenuStatusExtender
Inherits Component
Implements IExtenderProvider
Private _extendees As New Hashtable
Public Sub New()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
Dim mi As MenuItem
If Not Me.DesignMode Then
For Each mi In _extendees.Keys
RemoveHandler mi.Select, AddressOf Me.MenuStatusExtender_Select
Next
End If
_extendees.Clear()
MyBase.Dispose(disposing)
End Sub
Public Overridable Function CanExtend(ByVal extendee As [Object]) As Boolean
Implements IExtenderProvider.CanExtend
Return TypeOf extendee Is MenuItem
End Function
Public Function GetStatusText(ByVal item As MenuItem) As String
If _extendees.ContainsKey(item) Then
Return CType(_extendees(item), String)
Else
Return ""
End If
End Function
Public Sub SetStatusText(ByVal item As MenuItem, ByVal s As String)
If _extendees.ContainsKey(item) Then
_extendees(item) = s
Else
If Not Me.DesignMode Then
AddHandler item.Select, AddressOf Me.MenuStatusExtender_Select
End If
_extendees.Add(item, s)
End If
End Sub
Private Sub MenuStatusExtender_Select(ByVal sender As Object, ByVal e As
EventArgs)
OnItemSelected(New ItemSelectEventArgs(_extendees(sender)))
End Sub
Private Sub OnItemSelected(ByVal e As ItemSelectEventArgs)
RaiseEvent ItemSelected(Me, e)
End Sub
Public Event ItemSelected As ItemSelectEventHandler
End Class
Public Class ItemSelectEventArgs
Inherits EventArgs
Private _statusMessage As String
Protected Sub New()
End Sub
Public Sub New(ByVal message As String)
_statusMessage = message
End Sub
Public ReadOnly Property StatusMessage() As String
Get
Return _statusMessage
End Get
End Property
End Class
Public Delegate Sub ItemSelectEventHandler(ByVal sender As Object, ByVal e
As ItemSelectEventArgs)
"Miky" <no****@virtuelcom.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... Hi,
I'm looking resources or tutorial where I can learn how to add
properties to other objects at design time for VB.NEt or C#.
I want to reproduce the same effect as when your drop the tooltip object
on a form. Once it's done, every object has a new property added to the
property box so we can write the tooltip text.
Syncfusion object does something like that when we drop a docking
manager tool. It adds 3 new properties to every object that can use this
resources.
I tried to find information but maybe because I don't know how to call
that effect, I was not succesfull to find information.
Thank you very much.
Miky
*** Sent via Developersdex http://www.developersdex.com ***