| < Free Open Study > |
|
Properties of a form are referenced through the IDesignerHost object. It is actually complex and abstract, but once you learn how to reference one property, you can then reference any property the same way.
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 sSize As String = _ pd.GetValue(fdHost.RootComponent).ToString() MsgBox("Default Form Size = " & sSize) End If
| < Free Open Study > |
|