Reference Properties of a Control on a Form

 < Free Open Study > 

Change a Property on a Form

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 > 

Writing Add-Ins for Visual Studio  .NET
Writing Add-Ins for Visual Studio .NET
ISBN: 1590590260
EAN: 2147483647
Year: 2002
Pages: 172
Authors: Les Smith © 2008-2017.
If you may any questions please contact us: