PropertyGrid(属性表)控件主要是用来显示类中的各种属性,我们还可以在此控件中修改属性值。
此控件使用非常简单,我们只需要将要显示的对象赋值给SelectedObject属性即可。
下面是命令按钮中写的代码,其实核心代码就一句,将要显示的对象赋值给PropertyGrid.SelectedObject。
Vb.Net |
Public Sub btnShowProperty_Click(sender As Object,e As System.EventArgs) Dim SmGrid1 As SmGrid=Me.SmForm.ControlDictionary()("SmGrid1") Dim PropertyGrid1 As PropertyGrid=Me.SmForm.ControlDictionary()("PropertyGrid1") PropertyGrid1.SelectedObject=SmGrid1 End Sub |
C# |
public void btnShowProperty_Click(object sender, System.EventArgs e) { SmGrid SmGrid1 = this.SmForm.ControlDictionary()["SmGrid1"] as SmGrid; PropertyGrid PropertyGrid1 = this.SmForm.ControlDictionary()["PropertyGrid1"] as PropertyGrid; PropertyGrid1.SelectedObject = SmGrid1; } |