パネル内のすべてのコントロールを実行して、各コントロールに対してユーザーが変更したプロパティを見つけようとしています。
だから私はこのコードを持っています:
Private Sub WriteProperties(ByVal cntrl As Control)
Try
Dim oType As Type = cntrl.GetType
'Create a new control the same type as cntrl to use it as the default control
Dim newCnt As New Control
newCnt = Activator.CreateInstance(oType)
For Each prop As PropertyInfo In newCnt.GetType().GetProperties
Dim val = cntrl.GetType().GetProperty(prop.Name).GetValue(cntrl, Nothing)
Dim defVal = newCnt.GetType().GetProperty(prop.Name).GetValue(newCnt, Nothing)
If val.Equals(defVal) = False Then
'So if something is different....
End If
Next
Catch ex As Exception
MsgBox("WriteProperties : " & ex.Message)
End Try
End Sub
今、私は3つの問題に直面しています:
プロパティが画像 (BackGround Image) を参照すると、エラーが発生します: ImageObject 参照がオブジェクトのインスタンスに設定されていません。
2 番目の問題は、コード:
If val.Equals(defVal) = False Then 'So if something is different.... End If
val と defVal が同じ場合に実行されることがあります。これは、プロパティが FlatAppearance (より多くの子プロパティを持つ) のような「parentProperty」である場合に発生します。
私のループは、必要なサイズや場所などの基本的なプロパティを調べません