| < Free Open Study > |
|
Properties of components on a form are referenced through the IDesignerHost object, in much the same way that properties on a form are referenced.
The following code snippet references the Size property of a form. The Size property was chosen because a System.Drawing.Size object must be used, which is a little more involved than a simple String property. Note that the active window must contain a WinForms Designer. The comments in the code describe what is taking place in the code.
' Get a forms designer host object Dim fdHost As IDesignerHost If applicationObject.ActiveWindow.Caption. EndsWith("[Design]") Then Dim sName As String, sText As String fdHost = CType(applicationObject.ActiveWindow.Object, _ IDesignerHost) ' get property descriptor collection object ' properties of a form are referenced through ' the RootComponent ' of the designer host object Dim pdc As PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(fdHost.RootComponent) ' get property descriptor object Dim pd As PropertyDescriptor ' display size of form ' set property descriptor to point to size pd = pdc("Size") Dim sz As System.Drawing.Size sz = New Size(250, 400) pd.SetValue(fdHost.RootComponent, sz) End If
| < Free Open Study > |
|