PDA

View Full Version : سوال: کامپوننتی که Propertyهای اون به کنترل‌های Form اضافه بشه (مانند ErrorProvider یا Tooltip )



gilsoft
یک شنبه 30 شهریور 1393, 08:23 صبح
سلام دوستان

من یه کامپوننت نوشتم .. و میخوام هنگامیکه اونو به Form اضافه می‌کنم .. 3تا از Propertyهای اون به همه‌ی کنترل‌های موجود ( یا مثلا: به Panelها و Gridها ) در Form اضافه بشه ...

یعنی در واقع میخوام مانند کامپوننت ErrorProvider و یا Tooltip عمل کنه ... :چشمک:

حالا چکار باید بکنم ؟ :متفکر: :متفکر:

ممنون میشم راهنمایی بفرمائید .... :خجالت:

gilsoft
یک شنبه 30 شهریور 1393, 17:12 عصر
سلام دوستان ...

خودم پیدا کردم ....
میزارم همین‌جا تا شاید کسی ازش استفاده کرد:

Imports System.Windows.Forms
Imports System.ComponentModel


<ProvideProperty("MyProperty1", GetType(Control))> _
<ProvideProperty("MyProperty2", GetType(Control))> _
Public Class MyComponent
Implements IExtenderProvider


Public Function CanExtend(ByVal target As [Object]) As Boolean Implements IExtenderProvider.CanExtend
Return True
End Function


'My Property
Private _Enanble As Boolean
<DefaultValue(False), Category("Data"), Description("Adjust on Property the Type Boolean")> _
Public Property Enable() As Boolean
Get
Return _Enanble
End Get
Set(ByVal value As Boolean)
_Enanble = value
End Set
End Property


'My Global Property1
Private _MyProperty1 As New Dictionary(Of IntPtr, Color)
<DefaultValue(GetType(Color), "Red"), Category("Data"), Description("Adjust on Global Property the Type color")> _
Public Function GetMyProperty1(ByVal c As Control) As Color
Dim value As Color = Color.Red
_MyProperty1.TryGetValue(c.Handle, value)
Return value
End Function


<DefaultValue(GetType(Color), "Red"), Category("Data"), Description("Adjust on Global Property the Type Color")> _
Public Sub SetMyProperty1(ByVal c As Control, ByVal value As Color)
_MyProperty1(c.Handle) = value
End Sub


'My Global Property2
Private _MyProperty2 As New Dictionary(Of IntPtr, String)
<DefaultValue(""), Category("Data"), Description("Adjust on Global Property the Type String")> _
Public Function GetMyProperty2(ByVal c As Control) As String
Dim value As String = ""
_MyProperty2.TryGetValue(c.Handle, value)
Return value
End Function


<DefaultValue(""), Category("Data"), Description("Adjust on Global Property the Type String")> _
Public Sub SetMyProperty2(ByVal c As Control, ByVal value As String)
_MyProperty2(c.Handle) = value
End Sub


End Class

موفق باشید .....