Page 1 of 1

Property Grid Function

Posted: Sat Aug 07, 2010 10:34 pm
by PGilbert
You can use the following function to find and experiment with the properties of a .Net Object:

Code: Select all

 PGRID object;form;pgrid;sink;⎕USING
⍝ Program to Show the Properties of an Object using the .Net PropertyGrid Class
⍝ http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.aspx
⍝ Version 1.0 - August 2010 - Pierre Gilbert

⍝ object = Valid .Net Object
⍝ PGRID∆BOUNDS = Global Variable with the Last Size and Position of the Form

 ⎕USING←'System.Windows.Forms,System.Windows.Forms.dll' 'System.Drawing,System.Drawing.dll'

 :If 9≠⎕NC'object'
     'ERROR: Argument Must be a .Net Object' ⋄ →0
 :End

⍝ Check the Global Variable 'PGRID∆BOUNDS'
 :If 0≠⎕NC'PGRID∆BOUNDS'
 :AndIf 326=⎕DR PGRID∆BOUNDS
 :AndIf '(NULL)'≢⍕PGRID∆BOUNDS
 :AndIf 'System.Drawing.Rectangle'≡PGRID∆BOUNDS.GetType.ToString
    ⍝ Do Nothing PGRID∆BOUNDS exists and is Valid
 :Else
    ⍝ First Time, set the Default Location and Size of the Form
    ⍝ Set X=60, Y=80, WIDTH=330, HEIGHT=430
     PGRID∆BOUNDS←⎕NEW Rectangle(60 80 330 430)
 :EndIf

⍝ Create the Property Grid
 pgrid←⎕NEW PropertyGrid
 pgrid.Dock←pgrid.Dock.Fill
 pgrid.SelectedObject←object

⍝ Create the Form
 form←⎕NEW Form
 form.Bounds←PGRID∆BOUNDS
 form.StartPosition←form.StartPosition.Manual
 form.FormBorderStyle←form.FormBorderStyle.SizableToolWindow
 form.Text←'Property Grid'
 form.TopMost←1
 form.Controls.Add pgrid

⍝ Show the Form and Wait on it
 form.Show ⍬
 :While form.Visible ⋄ :EndWhile

⍝ The Form is Closed

⍝ Save the Actual Location and Size of the Form
 PGRID∆BOUNDS←form.Bounds

⍝ Dispose the Form
 form.Dispose


For example if you do the following:

f←⎕new Form
PGRID f

You obtain:

PropertyGrid.png
PropertyGrid.png (22.51 KiB) Viewed 5814 times


Pierre Gilbert

P.S.: Thank to RossHale to help me finish the function