Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Salam
how can i declare a "strucure property" on other component in vb.net?

i use from this code
but i have a problem
the property information no save in parent form designer

i can not save property value on parent object in design mode

thank for your helps

VB
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms.Design
Imports System.Drawing.Design

<ProvideProperty("MyValue", GetType(Control))> _
Public Class SampleControl
    Inherits Component
    Implements IExtenderProvider

    Private mMyValues As Hashtable

    Public Sub New()
        mMyValues = New Hashtable()
    End Sub

    Function CanExtend(ByVal target As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf target Is SampleControl Then
            Return False
        ElseIf TypeOf target Is Control Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetMyValue(ByVal ctl As Control) As Sample_ST
        If mMyValues.ContainsKey(ctl) Then
            Return mMyValues(ctl)
        Else
            mMyValues.Add(ctl, New Sample_ST)
            Return mMyValues(ctl)
        End If
    End Function

    Public Sub SetMyValue(ByVal ctl As Control, ByVal value As Sample_ST)
        If Not mMyValues.ContainsKey(ctl) Then
            mMyValues.Add(ctl, value)
        End If
        mMyValues(ctl) = value
    End Sub

    <Editor(GetType(Sample_STUITypeEditor), GetType(UITypeEditor))> _
<TypeConverter(GetType(ExpandableObjectConverter))>
    Public Structure Sample_ST
        Public Code As Integer
        Public Name As String
        Public Family As String
        Public Overrides Function ToString() As String
            Return Name + " " + Family
        End Function
    End Structure
End Class

Public Class Sample_STUITypeEditor
    Inherits UITypeEditor

    Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
        Return UITypeEditorEditStyle.DropDown
    End Function

    Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
        Dim service As IWindowsFormsEditorService = provider.GetService(GetType(IWindowsFormsEditorService))
        If (service Is Nothing) Or (value Is Nothing) Then
            Return value
        End If

        Dim power As New SampleControl.Sample_ST

        power = value


        Using f As New PowerForm
            f.txtCode.Text = power.Code
            f.txtName.Text = power.Name
            f.txtFamily.Text = power.Family

            If service.ShowDialog(f) = DialogResult.OK Then
                power.Code = f.txtCode.Text
                power.Name = f.txtName.Text
                power.Family = f.txtFamily.Text
            End If
        End Using
        Return power

    End Function


End Class
Posted
Comments
Ch Smrutiranjan 20-Oct-14 9:15am    
Can you have a quick look at this: http://www.c-sharpcorner.com/UploadFile/rajeshvs/understanding-structures-in-VB-Net/
ms_vb 20-Oct-14 10:04am    
thank you for your comment
but i dont found my question answer on that link!
i want make a propery such as "tooltip" But that must declare as "Sample_ST" structure
Maciej Los 27-Oct-14 15:33pm    
Not sure what you mean by saying: "how to declare structure property"...
Do you want to return structure via component property?

Have you seen these:
Using Classes and Structures in Visual Basic .NET[^]
How to: Hold More Than One Value in a Variable (Visual Basic)[^]
Structures and Classes (Visual Basic)[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900