Reference All of the Selected Controls on a Form

 < Free Open Study > 

Change a Property of a Control on a Form

The following code snippet uses the IDesignerHost, the PropertyDescriptor, and PropertyDescriptorCollection to demonstrate changing the Size and Location properties of a button on a form. The code assumes that the active window contains a WinForms Designer. For additional details on manipulating controls and forms, see Chapter 6 and the code for that chapter.

   ' Get a forms designer host object   Dim fdHost As IDesignerHost   If applicationObject.ActiveWindow.Caption.      EndsWith("[Design]") Then      Try         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         Dim pdc As PropertyDescriptorCollection         pd = pdc("Size")         MsgBox("Default Button size = " & _            pd.GetValue(btn1).ToString())         ' resize the button         Dim sz As System.Drawing.Size         sz = New Size(100, 60)         pd.SetValue(btn1, sz)         MsgBox("custom Button size = " & _             pd.GetValue(btn1).ToString())         " reposition the button         pd = pdc("Location")         Dim loc As System.Drawing.Point         loc = New Point(30, 30)         pd.SetValue(btn1, loc)         MsgBox("New button location = " & _            pd.GetValue(btn1).ToString())      Catch e As System.Exception        MsgBox(e.Message)      End Try   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: