| < Free Open Study > |
|
The IDesignerHost object is used to reference properties of a form, as well as the properties of any of the components on the form.
The following code snippet demonstrates how to reference a property of the form. In this code, the Size property is referenced because it is a little different from a simple String property. To reference the Size property or the Location property, you must use the System.Drawing.Size object. The following code snippet assumes that the active window contains a WinForms Designer. The code is commented well enough to describe what is taking place in the code. For more details on manipulating controls, see Chapter 6 and the code for that chapter. Note that you must always have an IDesignerHost object to reference anything on a form, including the form's properties or component properties.
' 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 and set the value of the size proeprty, " showing values " before and after. Dim pd As PropertyDescriptor pd = pdc("Size") MsgBox("Default Button size = " + _ pd.GetValue(btn1).ToString()) Catch e As System.Exception MsgBox(e.Message) End Try End If
| < Free Open Study > |
|