オブジェクトプロパティのサンプル1
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[VisualBasic.NET]]~
[[オブジェクトプロパティ]]~
[[オブジェクトプロパティのサンプル2]]
* オブジェクト型のプロパティ [#wfb758e3]
'プロパティクラス
Public Class MyProperty
Event PropertyChanged(ByVal PropertyName As String)
Dim strA As String
Dim strB As String
Public Property a As String
Get
Return strA
End Get
Set(ByVal Value As String)
If strA <> Value Then
strA = Value
RaiseEvent PropertyChaged(a)
End If
End Set
End Property
Public Property b As String
Get
Return strB
End Get
Set(ByVal Value As String)
If strB <> Value Then
strB = Value
RaiseEvent PropertyChaged(b)
End If
End Set
End Property
Overrides Function ToString() As String
Return ”(MyProperty)”
End Function
End Class
'ユーザコントロール
Public Class MyControl
Inherits System.Windows.Forms.UserControl
+ Windows フォーム デザイナで生成されたコード
Dim WithEvents mMyProperty As New MyProperty()
<TypeConverter(GetType(MyPropertyTypeConverter))> _
Property CustomProperty As MyProperty
Get
Return mMyProperty
End Get
Set(ByVal Value As MyProperty)
mMyProperty = Value
End Set
End Property
End Class
'TypeConvertカスタムクラス
Public Class MyPropertyTypeConverter
Inherits TypeConverter
Overlodes Overrides Function GetPropertiesSupported( _
ByVal Context as ITypeDescriptorContext) As Boolean
Return True
End Function
Overlodes Overrides Function GetProperties( _
ByVal Context as ITypeDescriptorContext, _
ByVal Value As Object, _
ByVal attributes() As Attribute) As PropertyDescri...
Return TypeDescriptor.GetProperties(GetType(MyPr...
End Function
End Class
* 修正 [#ed876d1a]
上のプログラム例では、実行時に値が消えてしまう。値を永続...
- System.ComponentModel.DesignerSerializationVisibility属...
デザイン時にコンポーネントのプロパティをシリアライズ化す...
引数に永続化の種類を指定する。~
> [Context]:代入するオブジェクトの各プロパティを初期化。
> [Hidden] :初期化コードで永続化しない。
> [Visible]:初期化コードで永続化する。
'ユーザコントロール
Public Class MyControl
Inherits System.Windows.Forms.UserControl
+ Windows フォーム デザイナで生成されたコード
Dim WithEvents mMyProperty As New MyProperty()
<DesignerSerializationVisibility(Content), TypeConve...
Get
Return mMyProperty
End Get
Set(ByVal Value As MyProperty)
mMyProperty = Value
End Set
End Property
End Class
終了行:
[[VisualBasic.NET]]~
[[オブジェクトプロパティ]]~
[[オブジェクトプロパティのサンプル2]]
* オブジェクト型のプロパティ [#wfb758e3]
'プロパティクラス
Public Class MyProperty
Event PropertyChanged(ByVal PropertyName As String)
Dim strA As String
Dim strB As String
Public Property a As String
Get
Return strA
End Get
Set(ByVal Value As String)
If strA <> Value Then
strA = Value
RaiseEvent PropertyChaged(a)
End If
End Set
End Property
Public Property b As String
Get
Return strB
End Get
Set(ByVal Value As String)
If strB <> Value Then
strB = Value
RaiseEvent PropertyChaged(b)
End If
End Set
End Property
Overrides Function ToString() As String
Return ”(MyProperty)”
End Function
End Class
'ユーザコントロール
Public Class MyControl
Inherits System.Windows.Forms.UserControl
+ Windows フォーム デザイナで生成されたコード
Dim WithEvents mMyProperty As New MyProperty()
<TypeConverter(GetType(MyPropertyTypeConverter))> _
Property CustomProperty As MyProperty
Get
Return mMyProperty
End Get
Set(ByVal Value As MyProperty)
mMyProperty = Value
End Set
End Property
End Class
'TypeConvertカスタムクラス
Public Class MyPropertyTypeConverter
Inherits TypeConverter
Overlodes Overrides Function GetPropertiesSupported( _
ByVal Context as ITypeDescriptorContext) As Boolean
Return True
End Function
Overlodes Overrides Function GetProperties( _
ByVal Context as ITypeDescriptorContext, _
ByVal Value As Object, _
ByVal attributes() As Attribute) As PropertyDescri...
Return TypeDescriptor.GetProperties(GetType(MyPr...
End Function
End Class
* 修正 [#ed876d1a]
上のプログラム例では、実行時に値が消えてしまう。値を永続...
- System.ComponentModel.DesignerSerializationVisibility属...
デザイン時にコンポーネントのプロパティをシリアライズ化す...
引数に永続化の種類を指定する。~
> [Context]:代入するオブジェクトの各プロパティを初期化。
> [Hidden] :初期化コードで永続化しない。
> [Visible]:初期化コードで永続化する。
'ユーザコントロール
Public Class MyControl
Inherits System.Windows.Forms.UserControl
+ Windows フォーム デザイナで生成されたコード
Dim WithEvents mMyProperty As New MyProperty()
<DesignerSerializationVisibility(Content), TypeConve...
Get
Return mMyProperty
End Get
Set(ByVal Value As MyProperty)
mMyProperty = Value
End Set
End Property
End Class
ページ名: