473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

IExtenderProvider for Components

Is it possible to add an extended property to components like I can with controls via
IExtenderProvider?

JackRazz
Nov 20 '05 #1
8 2427
Yes, you can extend properties of controls or components.
JackRazz wrote:
Is it possible to add an extended property to components like I can with controls via
IExtenderProvider?

JackRazz

Nov 20 '05 #2
Yes, you can extend properties of controls or components.
JackRazz wrote:
Is it possible to add an extended property to components like I can with controls via
IExtenderProvider?

JackRazz

Nov 20 '05 #3
Yea Right,
You have been helping me quite a bit lately<grin>. Thanks for the info. I tried to
extend components and it didn't work. I'll look at it again a little more, since I
now know it should work.

Thanks - JackRazz

"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
| Yes, you can extend properties of controls or components.
|
|
| JackRazz wrote:
| > Is it possible to add an extended property to components like I can with controls
via
| > IExtenderProvider?
| >
| > JackRazz
| >
| >
Nov 20 '05 #4
Yea Right,
You have been helping me quite a bit lately<grin>. Thanks for the info. I tried to
extend components and it didn't work. I'll look at it again a little more, since I
now know it should work.

Thanks - JackRazz

"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
| Yes, you can extend properties of controls or components.
|
|
| JackRazz wrote:
| > Is it possible to add an extended property to components like I can with controls
via
| > IExtenderProvider?
| >
| > JackRazz
| >
| >
Nov 20 '05 #5
JackRazz, to prove that this is possible, I've extended the Timer
component to include an automatic shutoff after a certain number of
times called. Take a look to see how I did it.
Option Explicit On
Option Strict On

Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Timers

<ProvideProperty("AutoShutOff", GetType(Timers.Timer)), _
ProvideProperty("ShutOffValue", GetType(Timers.Timer))> _
Public Class TimerExtender
Inherits System.ComponentModel.Component
Implements IExtenderProvider

Friend ht As New Hashtable()
Dim value As Integer
#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region
Public Function CanExtend(ByVal extendee As Object) As Boolean
Implements System.ComponentModel.IExtenderProvider.CanExtend

If TypeOf extendee Is Timers.Timer Then
AddPropertyValue(DirectCast(extendee, Timers.Timer))
Return True
Else
Return False
End If

End Function


Private Function AddPropertyValue(ByVal ctrl As Timers.Timer) As
TimerExtendedProperties

If ht.Contains(ctrl) Then
Return CType(ht(ctrl), TimerExtendedProperties)
Else
Dim tbProperties As New TimerExtendedProperties()

ht.Add(ctrl, tbProperties)

AddHandler ctrl.Elapsed, AddressOf TimerElapsed

Return tbProperties

End If

End Function
Private Sub TimerElapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)

Dim ctrl As Timers.Timer = CType(sender, Timers.Timer)

value += 1

If value >= GetShutOffValue(ctrl) Then
ctrl.Enabled = False
value = 0
End If

End Sub

<Description("Enable automatic shutoff?"), _
DefaultValue(False)> _
Public Function GetAutoShutOff(ByVal ctrl As Timers.Timer) As Boolean

If ht.Contains(ctrl) Then
Return CType(ht(ctrl), TimerExtendedProperties).enabled
Else
Return False
End If
End Function

Public Sub SetAutoShutOff(ByVal ctrl As Timers.Timer, ByVal value
As Boolean)
AddPropertyValue(ctrl).enabled = value
End Sub

<Description("Value of when to shutoff timer."), _
DefaultValue(1)> _
Public Function GetShutOffValue(ByVal ctrl As Timers.Timer)As Integer

If ht.Contains(ctrl) Then
Return CType(ht(ctrl), TimerExtendedProperties).count
Else
Return 0
End If
End Function

Public Sub SetShutOffValue(ByVal ctrl As Timers.Timer, ByVal value
As Integer)
AddPropertyValue(ctrl).count = value
End Sub

End Class
Public Class TimerExtendedProperties
Public enabled As Boolean = False
Public count As Integer = 1
End Class
Nov 20 '05 #6
JackRazz, to prove that this is possible, I've extended the Timer
component to include an automatic shutoff after a certain number of
times called. Take a look to see how I did it.
Option Explicit On
Option Strict On

Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Timers

<ProvideProperty("AutoShutOff", GetType(Timers.Timer)), _
ProvideProperty("ShutOffValue", GetType(Timers.Timer))> _
Public Class TimerExtender
Inherits System.ComponentModel.Component
Implements IExtenderProvider

Friend ht As New Hashtable()
Dim value As Integer
#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region
Public Function CanExtend(ByVal extendee As Object) As Boolean
Implements System.ComponentModel.IExtenderProvider.CanExtend

If TypeOf extendee Is Timers.Timer Then
AddPropertyValue(DirectCast(extendee, Timers.Timer))
Return True
Else
Return False
End If

End Function


Private Function AddPropertyValue(ByVal ctrl As Timers.Timer) As
TimerExtendedProperties

If ht.Contains(ctrl) Then
Return CType(ht(ctrl), TimerExtendedProperties)
Else
Dim tbProperties As New TimerExtendedProperties()

ht.Add(ctrl, tbProperties)

AddHandler ctrl.Elapsed, AddressOf TimerElapsed

Return tbProperties

End If

End Function
Private Sub TimerElapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)

Dim ctrl As Timers.Timer = CType(sender, Timers.Timer)

value += 1

If value >= GetShutOffValue(ctrl) Then
ctrl.Enabled = False
value = 0
End If

End Sub

<Description("Enable automatic shutoff?"), _
DefaultValue(False)> _
Public Function GetAutoShutOff(ByVal ctrl As Timers.Timer) As Boolean

If ht.Contains(ctrl) Then
Return CType(ht(ctrl), TimerExtendedProperties).enabled
Else
Return False
End If
End Function

Public Sub SetAutoShutOff(ByVal ctrl As Timers.Timer, ByVal value
As Boolean)
AddPropertyValue(ctrl).enabled = value
End Sub

<Description("Value of when to shutoff timer."), _
DefaultValue(1)> _
Public Function GetShutOffValue(ByVal ctrl As Timers.Timer)As Integer

If ht.Contains(ctrl) Then
Return CType(ht(ctrl), TimerExtendedProperties).count
Else
Return 0
End If
End Function

Public Sub SetShutOffValue(ByVal ctrl As Timers.Timer, ByVal value
As Integer)
AddPropertyValue(ctrl).count = value
End Sub

End Class
Public Class TimerExtendedProperties
Public enabled As Boolean = False
Public count As Integer = 1
End Class
Nov 20 '05 #7
Yea Right,
Sorry, I havn't checked back on this in a while as I resolved it. My mistake that
first time was that I copied/pasted extender code from a control and forgot to change
the ProvideProperty.
I had a bit of figuring to do in order for the extended class to handle both
components and controls. After a bit of experimenting, I finally figured out that an
extender can handle both controls and components by simply using GetType(Components)
in the ProvideProperty attribute. I'm guessing this is because controls are
inherited from components.

On another note, I was trying to figure out how to get a components project name
during design time. I just ran across this snippet in a CodeProject example:
private static Object getProject()
{
return
Connect.Application.ActiveDocument.ProjectItem.Con tainingProject.FileName;
}

It looks like all I need a simple Connect class and I'm in business<grin>. Its
sometimes amazing how I learn something new about the Framework on a daily basis.

Thanks - JackRazz

"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
| JackRazz, to prove that this is possible, I've extended the Timer
| component to include an automatic shutoff after a certain number of
| times called. Take a look to see how I did it.
|
|
| Option Explicit On
| Option Strict On
|
| Imports System.ComponentModel
| Imports System.Windows.Forms
| Imports System.Timers
|
| <ProvideProperty("AutoShutOff", GetType(Timers.Timer)), _
| ProvideProperty("ShutOffValue", GetType(Timers.Timer))> _
| Public Class TimerExtender
| Inherits System.ComponentModel.Component
| Implements IExtenderProvider
|
| Friend ht As New Hashtable()
| Dim value As Integer
| #Region " Component Designer generated code "
|
| Public Sub New(ByVal Container As System.ComponentModel.IContainer)
| MyClass.New()
|
| 'Required for Windows.Forms Class Composition Designer support
| Container.Add(Me)
| End Sub
|
| Public Sub New()
| MyBase.New()
|
| 'This call is required by the Component Designer.
| InitializeComponent()
|
| 'Add any initialization after the InitializeComponent() call
|
| End Sub
|
| 'Component overrides dispose to clean up the component list.
| Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
| If disposing Then
| If Not (components Is Nothing) Then
| components.Dispose()
| End If
| End If
| MyBase.Dispose(disposing)
| End Sub
|
| 'Required by the Component Designer
| Private components As System.ComponentModel.IContainer
|
| 'NOTE: The following procedure is required by the Component Designer
| 'It can be modified using the Component Designer.
| 'Do not modify it using the code editor.
| <System.Diagnostics.DebuggerStepThrough()> Private Sub
| InitializeComponent()
| components = New System.ComponentModel.Container()
| End Sub
|
| #End Region
|
|
| Public Function CanExtend(ByVal extendee As Object) As Boolean
| Implements System.ComponentModel.IExtenderProvider.CanExtend
|
| If TypeOf extendee Is Timers.Timer Then
| AddPropertyValue(DirectCast(extendee, Timers.Timer))
| Return True
| Else
| Return False
| End If
|
| End Function
|
|
|
|
| Private Function AddPropertyValue(ByVal ctrl As Timers.Timer) As
| TimerExtendedProperties
|
| If ht.Contains(ctrl) Then
| Return CType(ht(ctrl), TimerExtendedProperties)
| Else
| Dim tbProperties As New TimerExtendedProperties()
|
| ht.Add(ctrl, tbProperties)
|
| AddHandler ctrl.Elapsed, AddressOf TimerElapsed
|
| Return tbProperties
|
| End If
|
| End Function
|
|
| Private Sub TimerElapsed(ByVal sender As System.Object, ByVal e As
| System.Timers.ElapsedEventArgs)
|
| Dim ctrl As Timers.Timer = CType(sender, Timers.Timer)
|
| value += 1
|
| If value >= GetShutOffValue(ctrl) Then
| ctrl.Enabled = False
| value = 0
| End If
|
| End Sub
|
|
|
| <Description("Enable automatic shutoff?"), _
| DefaultValue(False)> _
| Public Function GetAutoShutOff(ByVal ctrl As Timers.Timer) As Boolean
|
| If ht.Contains(ctrl) Then
| Return CType(ht(ctrl), TimerExtendedProperties).enabled
| Else
| Return False
| End If
|
|
| End Function
|
| Public Sub SetAutoShutOff(ByVal ctrl As Timers.Timer, ByVal value
| As Boolean)
| AddPropertyValue(ctrl).enabled = value
| End Sub
|
| <Description("Value of when to shutoff timer."), _
| DefaultValue(1)> _
| Public Function GetShutOffValue(ByVal ctrl As Timers.Timer)As Integer
|
| If ht.Contains(ctrl) Then
| Return CType(ht(ctrl), TimerExtendedProperties).count
| Else
| Return 0
| End If
|
|
| End Function
|
| Public Sub SetShutOffValue(ByVal ctrl As Timers.Timer, ByVal value
| As Integer)
| AddPropertyValue(ctrl).count = value
| End Sub
|
|
|
| End Class
|
|
| Public Class TimerExtendedProperties
| Public enabled As Boolean = False
| Public count As Integer = 1
| End Class
Nov 20 '05 #8
Yea Right,
Sorry, I havn't checked back on this in a while as I resolved it. My mistake that
first time was that I copied/pasted extender code from a control and forgot to change
the ProvideProperty.
I had a bit of figuring to do in order for the extended class to handle both
components and controls. After a bit of experimenting, I finally figured out that an
extender can handle both controls and components by simply using GetType(Components)
in the ProvideProperty attribute. I'm guessing this is because controls are
inherited from components.

On another note, I was trying to figure out how to get a components project name
during design time. I just ran across this snippet in a CodeProject example:
private static Object getProject()
{
return
Connect.Application.ActiveDocument.ProjectItem.Con tainingProject.FileName;
}

It looks like all I need a simple Connect class and I'm in business<grin>. Its
sometimes amazing how I learn something new about the Framework on a daily basis.

Thanks - JackRazz

"yEaH rIgHt" <no******@haha.com> wrote in message
news:10*************@corp.supernews.com...
| JackRazz, to prove that this is possible, I've extended the Timer
| component to include an automatic shutoff after a certain number of
| times called. Take a look to see how I did it.
|
|
| Option Explicit On
| Option Strict On
|
| Imports System.ComponentModel
| Imports System.Windows.Forms
| Imports System.Timers
|
| <ProvideProperty("AutoShutOff", GetType(Timers.Timer)), _
| ProvideProperty("ShutOffValue", GetType(Timers.Timer))> _
| Public Class TimerExtender
| Inherits System.ComponentModel.Component
| Implements IExtenderProvider
|
| Friend ht As New Hashtable()
| Dim value As Integer
| #Region " Component Designer generated code "
|
| Public Sub New(ByVal Container As System.ComponentModel.IContainer)
| MyClass.New()
|
| 'Required for Windows.Forms Class Composition Designer support
| Container.Add(Me)
| End Sub
|
| Public Sub New()
| MyBase.New()
|
| 'This call is required by the Component Designer.
| InitializeComponent()
|
| 'Add any initialization after the InitializeComponent() call
|
| End Sub
|
| 'Component overrides dispose to clean up the component list.
| Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
| If disposing Then
| If Not (components Is Nothing) Then
| components.Dispose()
| End If
| End If
| MyBase.Dispose(disposing)
| End Sub
|
| 'Required by the Component Designer
| Private components As System.ComponentModel.IContainer
|
| 'NOTE: The following procedure is required by the Component Designer
| 'It can be modified using the Component Designer.
| 'Do not modify it using the code editor.
| <System.Diagnostics.DebuggerStepThrough()> Private Sub
| InitializeComponent()
| components = New System.ComponentModel.Container()
| End Sub
|
| #End Region
|
|
| Public Function CanExtend(ByVal extendee As Object) As Boolean
| Implements System.ComponentModel.IExtenderProvider.CanExtend
|
| If TypeOf extendee Is Timers.Timer Then
| AddPropertyValue(DirectCast(extendee, Timers.Timer))
| Return True
| Else
| Return False
| End If
|
| End Function
|
|
|
|
| Private Function AddPropertyValue(ByVal ctrl As Timers.Timer) As
| TimerExtendedProperties
|
| If ht.Contains(ctrl) Then
| Return CType(ht(ctrl), TimerExtendedProperties)
| Else
| Dim tbProperties As New TimerExtendedProperties()
|
| ht.Add(ctrl, tbProperties)
|
| AddHandler ctrl.Elapsed, AddressOf TimerElapsed
|
| Return tbProperties
|
| End If
|
| End Function
|
|
| Private Sub TimerElapsed(ByVal sender As System.Object, ByVal e As
| System.Timers.ElapsedEventArgs)
|
| Dim ctrl As Timers.Timer = CType(sender, Timers.Timer)
|
| value += 1
|
| If value >= GetShutOffValue(ctrl) Then
| ctrl.Enabled = False
| value = 0
| End If
|
| End Sub
|
|
|
| <Description("Enable automatic shutoff?"), _
| DefaultValue(False)> _
| Public Function GetAutoShutOff(ByVal ctrl As Timers.Timer) As Boolean
|
| If ht.Contains(ctrl) Then
| Return CType(ht(ctrl), TimerExtendedProperties).enabled
| Else
| Return False
| End If
|
|
| End Function
|
| Public Sub SetAutoShutOff(ByVal ctrl As Timers.Timer, ByVal value
| As Boolean)
| AddPropertyValue(ctrl).enabled = value
| End Sub
|
| <Description("Value of when to shutoff timer."), _
| DefaultValue(1)> _
| Public Function GetShutOffValue(ByVal ctrl As Timers.Timer)As Integer
|
| If ht.Contains(ctrl) Then
| Return CType(ht(ctrl), TimerExtendedProperties).count
| Else
| Return 0
| End If
|
|
| End Function
|
| Public Sub SetShutOffValue(ByVal ctrl As Timers.Timer, ByVal value
| As Integer)
| AddPropertyValue(ctrl).count = value
| End Sub
|
|
|
| End Class
|
|
| Public Class TimerExtendedProperties
| Public enabled As Boolean = False
| Public count As Integer = 1
| End Class
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Yasutaka Ito | last post by:
Hi, As you know, all the non-ui components (like Timer control, etc.) that sit on the form are contained in its private variable 'components'. How can I enumerate such components from any form...
4
by: james | last post by:
I have a custom UserControl, which can have many sub class levels derived from it. I want to be able to discover all the components at Load time, but the only components I can see from the base...
0
by: JessCurious | last post by:
after reading Bob Powell's excellent article in WellFormed it occurred to me that IExtenderProvider is probably how VS implements ToolTips as a property (was a mystery!). 1. is it confusing to...
0
by: Genival P.Carvalho | last post by:
Hello folks, First sorry my bad english. I will try to implement a IExtenderProvider + Verbs (Designer). When compile tha follow code its compile fine, but whem drag resulting componet under form...
7
by: JackRazz | last post by:
Is it possible to add an extended property to components like I can with controls via IExtenderProvider? JackRazz
1
by: Phill. W | last post by:
I understand how to use the IExtenderProvider Interface to add a "dynamic" property to a Control, but is there any equivalent "mechanism" for using this extendability with just /any-old/ class,...
0
by: Mark Collard | last post by:
When you add a ToolTip component to a Form (or UserControl) the other controls on the form display a ToolTip property in the property grid. This is because it implements the IExtenderProvider...
0
by: =?Utf-8?B?VHJpc3RlbiBGaWVsZGluZw==?= | last post by:
I've added an IExtenderProvider interface to a class called RadioButtonGroupPanel (which derives from Panel) and have added the attribute called . I've defined the following members: public...
0
by: J.B. Moreno | last post by:
Hello, I'm migrating a VB6 app to .Net and of course it uses the DataField property for databinding, which of course isn't available under .Net. On several forms it also uses the Tag property...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.