Server/FormEditObject.cs
author Stephane Lenclud
Fri, 19 Aug 2016 17:12:54 +0200
changeset 243 cc2251d065db
parent 239 dd7770b97916
child 244 2e4d2558bb21
permissions -rw-r--r--
Optical drive eject action now functional.
StephaneLenclud@231
     1
using System;
StephaneLenclud@231
     2
using System.Collections.Generic;
StephaneLenclud@231
     3
using System.ComponentModel;
StephaneLenclud@231
     4
using System.Data;
StephaneLenclud@231
     5
using System.Diagnostics;
StephaneLenclud@231
     6
using System.Drawing;
StephaneLenclud@231
     7
using System.Linq;
StephaneLenclud@231
     8
using System.Text;
StephaneLenclud@231
     9
using System.Threading.Tasks;
StephaneLenclud@231
    10
using System.Windows.Forms;
StephaneLenclud@231
    11
using SharpLib.Display;
StephaneLenclud@231
    12
using SharpLib.Ear;
StephaneLenclud@231
    13
using System.Reflection;
StephaneLenclud@231
    14
using Microsoft.VisualBasic.CompilerServices;
StephaneLenclud@231
    15
using SharpLib.Utils;
StephaneLenclud@238
    16
using CodeProject.Dialog;
StephaneLenclud@239
    17
using System.IO;
StephaneLenclud@231
    18
StephaneLenclud@231
    19
namespace SharpDisplayManager
StephaneLenclud@231
    20
{
StephaneLenclud@231
    21
    /// <summary>
StephaneLenclud@231
    22
    /// Object edit dialog form.
StephaneLenclud@231
    23
    /// </summary>
StephaneLenclud@239
    24
    public partial class FormEditObject<T> : Form where T: SharpLib.Ear.Object
StephaneLenclud@231
    25
    {
StephaneLenclud@231
    26
        public T Object = null;
StephaneLenclud@231
    27
StephaneLenclud@231
    28
        public FormEditObject()
StephaneLenclud@231
    29
        {
StephaneLenclud@231
    30
            InitializeComponent();
StephaneLenclud@231
    31
        }
StephaneLenclud@231
    32
StephaneLenclud@231
    33
        /// <summary>
StephaneLenclud@231
    34
        /// 
StephaneLenclud@231
    35
        /// </summary>
StephaneLenclud@231
    36
        /// <param name="sender"></param>
StephaneLenclud@231
    37
        /// <param name="e"></param>
StephaneLenclud@231
    38
        private void FormEditAction_Load(object sender, EventArgs e)
StephaneLenclud@231
    39
        {
StephaneLenclud@236
    40
            // Populate registered object types
StephaneLenclud@231
    41
            IEnumerable < Type > types = Reflection.GetConcreteClassesDerivedFrom<T>();
StephaneLenclud@231
    42
            foreach (Type type in types)
StephaneLenclud@231
    43
            {
StephaneLenclud@231
    44
                ItemObjectType item = new ItemObjectType(type);
StephaneLenclud@231
    45
                comboBoxActionType.Items.Add(item);
StephaneLenclud@231
    46
            }
StephaneLenclud@231
    47
StephaneLenclud@231
    48
            if (Object == null)
StephaneLenclud@231
    49
            {
StephaneLenclud@231
    50
                // Creating new issue, select our first item
StephaneLenclud@231
    51
                comboBoxActionType.SelectedIndex = 0;
StephaneLenclud@231
    52
            }
StephaneLenclud@231
    53
            else
StephaneLenclud@231
    54
            {
StephaneLenclud@231
    55
                // Editing existing object
StephaneLenclud@239
    56
                // Look up our item in our combobox
StephaneLenclud@231
    57
                foreach (ItemObjectType item in comboBoxActionType.Items)
StephaneLenclud@231
    58
                {
StephaneLenclud@231
    59
                    if (item.Type == Object.GetType())
StephaneLenclud@231
    60
                    {
StephaneLenclud@231
    61
                        comboBoxActionType.SelectedItem = item;
StephaneLenclud@231
    62
                    }
StephaneLenclud@231
    63
                }
StephaneLenclud@239
    64
            }
StephaneLenclud@231
    65
        }
StephaneLenclud@231
    66
StephaneLenclud@231
    67
        private void buttonOk_Click(object sender, EventArgs e)
StephaneLenclud@231
    68
        {
StephaneLenclud@231
    69
            FetchPropertiesValue(Object);
StephaneLenclud@239
    70
            if (!Object.IsValid())
StephaneLenclud@239
    71
            {
StephaneLenclud@239
    72
                // Tell for closing event to abort
StephaneLenclud@239
    73
                DialogResult = DialogResult.None;
StephaneLenclud@239
    74
            }
StephaneLenclud@231
    75
        }
StephaneLenclud@231
    76
StephaneLenclud@239
    77
StephaneLenclud@239
    78
        private void FormEditObject_FormClosing(object sender, FormClosingEventArgs e)
StephaneLenclud@231
    79
        {
StephaneLenclud@239
    80
            e.Cancel = DialogResult == DialogResult.None;
StephaneLenclud@231
    81
        }
StephaneLenclud@231
    82
StephaneLenclud@231
    83
        private void comboBoxActionType_SelectedIndexChanged(object sender, EventArgs e)
StephaneLenclud@231
    84
        {
StephaneLenclud@231
    85
            //Instantiate an action corresponding to our type
StephaneLenclud@231
    86
            Type actionType = ((ItemObjectType) comboBoxActionType.SelectedItem).Type;
StephaneLenclud@231
    87
            //Create another type of action only if needed
StephaneLenclud@231
    88
            if (Object == null || Object.GetType() != actionType)
StephaneLenclud@231
    89
            {
StephaneLenclud@231
    90
                Object = (T)Activator.CreateInstance(actionType);
StephaneLenclud@231
    91
            }
StephaneLenclud@239
    92
StephaneLenclud@239
    93
            //Disable ok button if our object is not valid
StephaneLenclud@239
    94
            buttonOk.Enabled = Object.IsValid();
StephaneLenclud@239
    95
StephaneLenclud@231
    96
            //Create input fields
StephaneLenclud@231
    97
            UpdateTableLayoutPanel(Object);
StephaneLenclud@231
    98
        }
StephaneLenclud@231
    99
StephaneLenclud@231
   100
StephaneLenclud@231
   101
        /// <summary>
StephaneLenclud@231
   102
        /// Get properties values from our generated input fields
StephaneLenclud@231
   103
        /// </summary>
StephaneLenclud@236
   104
        private void FetchPropertiesValue(T aObject)
StephaneLenclud@231
   105
        {
StephaneLenclud@231
   106
            int ctrlIndex = 0;
Stephane@243
   107
            //For each of our properties
StephaneLenclud@236
   108
            foreach (PropertyInfo pi in aObject.GetType().GetProperties())
StephaneLenclud@231
   109
            {
Stephane@243
   110
                //Get our property attribute
Stephane@243
   111
                AttributeObjectProperty[] attributes = ((AttributeObjectProperty[]) pi.GetCustomAttributes(typeof(AttributeObjectProperty), true));
StephaneLenclud@231
   112
                if (attributes.Length != 1)
StephaneLenclud@231
   113
                {
Stephane@243
   114
                    //No attribute, skip this property then.
StephaneLenclud@231
   115
                    continue;
StephaneLenclud@231
   116
                }
StephaneLenclud@231
   117
                AttributeObjectProperty attribute = attributes[0];
StephaneLenclud@231
   118
Stephane@243
   119
                //Check that we support this type of property
StephaneLenclud@231
   120
                if (!IsPropertyTypeSupported(pi))
StephaneLenclud@231
   121
                {
StephaneLenclud@231
   122
                    continue;
StephaneLenclud@231
   123
                }
StephaneLenclud@231
   124
Stephane@243
   125
                //Now fetch our property value
StephaneLenclud@236
   126
                GetPropertyValueFromControl(iTableLayoutPanel.Controls[ctrlIndex+1], pi, aObject); //+1 otherwise we get the label
StephaneLenclud@231
   127
StephaneLenclud@231
   128
                ctrlIndex+=2; //Jump over the label too
StephaneLenclud@231
   129
            }
StephaneLenclud@231
   130
        }
StephaneLenclud@231
   131
StephaneLenclud@231
   132
        /// <summary>
StephaneLenclud@231
   133
        /// Extend this function to support reading new types of properties.
StephaneLenclud@231
   134
        /// </summary>
StephaneLenclud@236
   135
        /// <param name="aObject"></param>
StephaneLenclud@236
   136
        private void GetPropertyValueFromControl(Control aControl, PropertyInfo aInfo, T aObject)
StephaneLenclud@231
   137
        {
StephaneLenclud@231
   138
            if (aInfo.PropertyType == typeof(int))
StephaneLenclud@231
   139
            {
StephaneLenclud@231
   140
                NumericUpDown ctrl=(NumericUpDown)aControl;
StephaneLenclud@236
   141
                aInfo.SetValue(aObject,(int)ctrl.Value);
StephaneLenclud@231
   142
            }
StephaneLenclud@231
   143
            else if (aInfo.PropertyType.IsEnum)
StephaneLenclud@231
   144
            {
StephaneLenclud@231
   145
                // Instantiate our enum
StephaneLenclud@231
   146
                object enumValue= Activator.CreateInstance(aInfo.PropertyType);
StephaneLenclud@231
   147
                // Parse our enum from combo box
StephaneLenclud@231
   148
                enumValue = Enum.Parse(aInfo.PropertyType,((ComboBox)aControl).SelectedItem.ToString());
StephaneLenclud@231
   149
                //enumValue = ((ComboBox)aControl).SelectedValue;
StephaneLenclud@231
   150
                // Set enum value
StephaneLenclud@236
   151
                aInfo.SetValue(aObject, enumValue);
StephaneLenclud@231
   152
            }
StephaneLenclud@231
   153
            else if (aInfo.PropertyType == typeof(bool))
StephaneLenclud@231
   154
            {
StephaneLenclud@231
   155
                CheckBox ctrl = (CheckBox)aControl;
StephaneLenclud@236
   156
                aInfo.SetValue(aObject, ctrl.Checked);
StephaneLenclud@231
   157
            }
StephaneLenclud@231
   158
            else if (aInfo.PropertyType == typeof(string))
StephaneLenclud@231
   159
            {
StephaneLenclud@231
   160
                TextBox ctrl = (TextBox)aControl;
StephaneLenclud@236
   161
                aInfo.SetValue(aObject, ctrl.Text);
StephaneLenclud@231
   162
            }
StephaneLenclud@238
   163
            else if (aInfo.PropertyType == typeof(PropertyFile))
StephaneLenclud@238
   164
            {
StephaneLenclud@238
   165
                Button ctrl = (Button)aControl;
StephaneLenclud@238
   166
                PropertyFile value = new PropertyFile {FullPath=ctrl.Text};
StephaneLenclud@238
   167
                aInfo.SetValue(aObject, value);
StephaneLenclud@238
   168
            }
Stephane@243
   169
            else if (aInfo.PropertyType == typeof(PropertyComboBox))
Stephane@243
   170
            {
Stephane@243
   171
                ComboBox ctrl = (ComboBox)aControl;
Stephane@243
   172
                string currentItem = ctrl.SelectedItem.ToString();
Stephane@243
   173
                PropertyComboBox pcb = (PropertyComboBox)aInfo.GetValue(aObject);
Stephane@243
   174
                pcb.CurrentItem = currentItem;
Stephane@243
   175
            }
Stephane@243
   176
StephaneLenclud@231
   177
            //TODO: add support for other types here
StephaneLenclud@231
   178
        }
StephaneLenclud@231
   179
StephaneLenclud@236
   180
StephaneLenclud@231
   181
        /// <summary>
StephaneLenclud@236
   182
        /// Create a control for the given property.
StephaneLenclud@231
   183
        /// </summary>
StephaneLenclud@231
   184
        /// <param name="aInfo"></param>
StephaneLenclud@236
   185
        /// <param name="aAttribute"></param>
StephaneLenclud@236
   186
        /// <param name="aObject"></param>
StephaneLenclud@236
   187
        /// <returns></returns>
StephaneLenclud@236
   188
        private Control CreateControlForProperty(PropertyInfo aInfo, AttributeObjectProperty aAttribute, T aObject)
StephaneLenclud@231
   189
        {
StephaneLenclud@231
   190
            if (aInfo.PropertyType == typeof(int))
StephaneLenclud@231
   191
            {
StephaneLenclud@231
   192
                //Integer properties are using numeric editor
StephaneLenclud@231
   193
                NumericUpDown ctrl = new NumericUpDown();
StephaneLenclud@231
   194
                ctrl.AutoSize = true;
StephaneLenclud@231
   195
                ctrl.Minimum = Int32.Parse(aAttribute.Minimum);
StephaneLenclud@231
   196
                ctrl.Maximum = Int32.Parse(aAttribute.Maximum);
StephaneLenclud@231
   197
                ctrl.Increment = Int32.Parse(aAttribute.Increment);
StephaneLenclud@236
   198
                ctrl.Value = (int)aInfo.GetValue(aObject);
StephaneLenclud@231
   199
                return ctrl;
StephaneLenclud@231
   200
            }
StephaneLenclud@231
   201
            else if (aInfo.PropertyType.IsEnum)
StephaneLenclud@231
   202
            {
StephaneLenclud@231
   203
                //Enum properties are using combo box
StephaneLenclud@231
   204
                ComboBox ctrl = new ComboBox();
Stephane@243
   205
                ctrl.AutoSize = true;
Stephane@243
   206
                ctrl.Sorted = true;
StephaneLenclud@231
   207
                ctrl.DropDownStyle = ComboBoxStyle.DropDownList;
StephaneLenclud@231
   208
                //Data source is fine but it gives us duplicate entries for duplicated enum values
StephaneLenclud@231
   209
                //ctrl.DataSource = Enum.GetValues(aInfo.PropertyType);
StephaneLenclud@231
   210
StephaneLenclud@231
   211
                //Therefore we need to explicitly create our items
Stephane@243
   212
                Size cbSize = new Size(0, 0);
StephaneLenclud@231
   213
                foreach (string name in aInfo.PropertyType.GetEnumNames())
StephaneLenclud@231
   214
                {
StephaneLenclud@231
   215
                    ctrl.Items.Add(name.ToString());
StephaneLenclud@231
   216
                    Graphics g = this.CreateGraphics();
StephaneLenclud@231
   217
                    //Since combobox autosize would not work we need to get measure text ourselves
Stephane@243
   218
                    SizeF size = g.MeasureString(name.ToString(), ctrl.Font);
Stephane@243
   219
                    cbSize.Width = Math.Max(cbSize.Width, (int)size.Width);
StephaneLenclud@231
   220
                    cbSize.Height = Math.Max(cbSize.Height, (int)size.Height);
StephaneLenclud@231
   221
                }
StephaneLenclud@231
   222
StephaneLenclud@231
   223
                //Make sure our combobox is large enough
StephaneLenclud@231
   224
                ctrl.MinimumSize = cbSize;
StephaneLenclud@231
   225
StephaneLenclud@231
   226
                // Instantiate our enum
StephaneLenclud@231
   227
                object enumValue = Activator.CreateInstance(aInfo.PropertyType);
StephaneLenclud@236
   228
                enumValue = aInfo.GetValue(aObject);
StephaneLenclud@231
   229
                //Set the current item
StephaneLenclud@231
   230
                ctrl.SelectedItem = enumValue.ToString();
StephaneLenclud@231
   231
StephaneLenclud@231
   232
                return ctrl;
StephaneLenclud@231
   233
            }
StephaneLenclud@231
   234
            else if (aInfo.PropertyType == typeof(bool))
StephaneLenclud@231
   235
            {
StephaneLenclud@231
   236
                CheckBox ctrl = new CheckBox();
StephaneLenclud@231
   237
                ctrl.AutoSize = true;
StephaneLenclud@231
   238
                ctrl.Text = aAttribute.Description;
Stephane@243
   239
                ctrl.Checked = (bool)aInfo.GetValue(aObject);
StephaneLenclud@231
   240
                return ctrl;
StephaneLenclud@231
   241
            }
StephaneLenclud@231
   242
            else if (aInfo.PropertyType == typeof(string))
StephaneLenclud@231
   243
            {
StephaneLenclud@231
   244
                TextBox ctrl = new TextBox();
StephaneLenclud@231
   245
                ctrl.AutoSize = true;
StephaneLenclud@236
   246
                ctrl.Text = (string)aInfo.GetValue(aObject);
StephaneLenclud@231
   247
                return ctrl;
StephaneLenclud@231
   248
            }
StephaneLenclud@238
   249
            else if (aInfo.PropertyType == typeof(PropertyFile))
StephaneLenclud@238
   250
            {
StephaneLenclud@238
   251
                // We have a file property
StephaneLenclud@238
   252
                // Create a button that will trigger the open file dialog to select our file.
StephaneLenclud@238
   253
                Button ctrl = new Button();
StephaneLenclud@238
   254
                ctrl.AutoSize = true;
StephaneLenclud@238
   255
                ctrl.Text = ((PropertyFile)aInfo.GetValue(aObject)).FullPath;
StephaneLenclud@239
   256
StephaneLenclud@238
   257
                // Add lambda expression to Click event
StephaneLenclud@238
   258
                ctrl.Click += (sender, e) =>
StephaneLenclud@238
   259
                {
StephaneLenclud@238
   260
                    // Create open file dialog
StephaneLenclud@238
   261
                    OpenFileDialog ofd = new OpenFileDialog();
StephaneLenclud@238
   262
                    ofd.RestoreDirectory = true;
StephaneLenclud@238
   263
                    // Use file filter specified by our property
StephaneLenclud@238
   264
                    ofd.Filter = aAttribute.Filter;
StephaneLenclud@238
   265
                    // Show our dialog
StephaneLenclud@238
   266
                    if (DlgBox.ShowDialog(ofd) == DialogResult.OK)
StephaneLenclud@238
   267
                    {
StephaneLenclud@238
   268
                        // Fetch selected file name
StephaneLenclud@238
   269
                        ctrl.Text = ofd.FileName;
StephaneLenclud@239
   270
                        //Enable Ok button then
StephaneLenclud@239
   271
                        buttonOk.Enabled = Object.IsValid();
StephaneLenclud@238
   272
                    }
StephaneLenclud@238
   273
                };
StephaneLenclud@238
   274
StephaneLenclud@238
   275
                return ctrl;
StephaneLenclud@238
   276
            }
Stephane@243
   277
            else if (aInfo.PropertyType == typeof(PropertyComboBox))
Stephane@243
   278
            {
Stephane@243
   279
                //ComboBox property
Stephane@243
   280
                ComboBox ctrl = new ComboBox();
Stephane@243
   281
                ctrl.AutoSize = true;
Stephane@243
   282
                ctrl.Sorted = true;
Stephane@243
   283
                ctrl.DropDownStyle = ComboBoxStyle.DropDownList;
Stephane@243
   284
                //Data source is such a pain to set the current item
Stephane@243
   285
                //ctrl.DataSource = ((PropertyComboBox)aInfo.GetValue(aObject)).Items;                
Stephane@243
   286
Stephane@243
   287
                PropertyComboBox pcb = ((PropertyComboBox)aInfo.GetValue(aObject));
Stephane@243
   288
                foreach (string item in pcb.Items)
Stephane@243
   289
                {
Stephane@243
   290
                    ctrl.Items.Add(item);
Stephane@243
   291
                }
Stephane@243
   292
Stephane@243
   293
                ctrl.SelectedItem = ((PropertyComboBox)aInfo.GetValue(aObject)).CurrentItem;
Stephane@243
   294
                //
Stephane@243
   295
                return ctrl;
Stephane@243
   296
            }
StephaneLenclud@231
   297
            //TODO: add support for other control type here
StephaneLenclud@231
   298
            return null;
StephaneLenclud@231
   299
        }
StephaneLenclud@231
   300
StephaneLenclud@231
   301
        /// <summary>
StephaneLenclud@231
   302
        /// Don't forget to extend that one and adding types
StephaneLenclud@231
   303
        /// </summary>
StephaneLenclud@231
   304
        /// <returns></returns>
StephaneLenclud@231
   305
        private bool IsPropertyTypeSupported(PropertyInfo aInfo)
StephaneLenclud@231
   306
        {
StephaneLenclud@231
   307
            if (aInfo.PropertyType == typeof(int))
StephaneLenclud@231
   308
            {
StephaneLenclud@231
   309
                return true;
StephaneLenclud@231
   310
            }
StephaneLenclud@231
   311
            else if (aInfo.PropertyType.IsEnum)
StephaneLenclud@231
   312
            {
StephaneLenclud@231
   313
                return true;
StephaneLenclud@231
   314
            }
StephaneLenclud@231
   315
            else if (aInfo.PropertyType == typeof(bool))
StephaneLenclud@231
   316
            {
StephaneLenclud@231
   317
                return true;
StephaneLenclud@231
   318
            }
StephaneLenclud@231
   319
            else if (aInfo.PropertyType == typeof(string))
StephaneLenclud@231
   320
            {
StephaneLenclud@231
   321
                return true;
StephaneLenclud@231
   322
            }
StephaneLenclud@238
   323
            else if (aInfo.PropertyType == typeof(PropertyFile))
StephaneLenclud@238
   324
            {
StephaneLenclud@238
   325
                return true;
StephaneLenclud@238
   326
            }
Stephane@243
   327
            else if (aInfo.PropertyType == typeof(PropertyComboBox))
Stephane@243
   328
            {
Stephane@243
   329
                return true;
Stephane@243
   330
            }
Stephane@243
   331
StephaneLenclud@231
   332
            //TODO: add support for other type here
StephaneLenclud@231
   333
StephaneLenclud@231
   334
            return false;
StephaneLenclud@231
   335
        }
StephaneLenclud@231
   336
StephaneLenclud@231
   337
        /// <summary>
StephaneLenclud@231
   338
        /// Update our table layout.
StephaneLenclud@231
   339
        /// Will instantiated every field control as defined by our action.
StephaneLenclud@231
   340
        /// Fields must be specified by rows from the left.
StephaneLenclud@231
   341
        /// </summary>
StephaneLenclud@231
   342
        /// <param name="aLayout"></param>
StephaneLenclud@236
   343
        private void UpdateTableLayoutPanel(T aObject)
StephaneLenclud@231
   344
        {
StephaneLenclud@231
   345
            toolTip.RemoveAll();
StephaneLenclud@231
   346
            //Debug.Print("UpdateTableLayoutPanel")
StephaneLenclud@231
   347
            //First clean our current panel
StephaneLenclud@231
   348
            iTableLayoutPanel.Controls.Clear();
StephaneLenclud@231
   349
            iTableLayoutPanel.RowStyles.Clear();
StephaneLenclud@231
   350
            iTableLayoutPanel.ColumnStyles.Clear();
StephaneLenclud@231
   351
            iTableLayoutPanel.RowCount = 0;
StephaneLenclud@231
   352
StephaneLenclud@231
   353
            //We always want two columns: one for label and one for the field
StephaneLenclud@231
   354
            iTableLayoutPanel.ColumnCount = 2;
StephaneLenclud@231
   355
            iTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
StephaneLenclud@231
   356
            iTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
StephaneLenclud@231
   357
StephaneLenclud@231
   358
StephaneLenclud@236
   359
            if (aObject == null)
StephaneLenclud@231
   360
            {
StephaneLenclud@231
   361
                //Just drop it
StephaneLenclud@231
   362
                return;
StephaneLenclud@231
   363
            }
StephaneLenclud@231
   364
            
StephaneLenclud@236
   365
            //IEnumerable<PropertyInfo> properties = aObject.GetType().GetProperties().Where(
StephaneLenclud@231
   366
            //    prop => Attribute.IsDefined(prop, typeof(AttributeObjectProperty)));
StephaneLenclud@231
   367
StephaneLenclud@231
   368
StephaneLenclud@236
   369
            foreach (PropertyInfo pi in aObject.GetType().GetProperties())
StephaneLenclud@231
   370
            {
StephaneLenclud@231
   371
                AttributeObjectProperty[] attributes = ((AttributeObjectProperty[])pi.GetCustomAttributes(typeof(AttributeObjectProperty), true));
StephaneLenclud@231
   372
                if (attributes.Length != 1)
StephaneLenclud@231
   373
                {
StephaneLenclud@231
   374
                    continue;
StephaneLenclud@231
   375
                }
StephaneLenclud@231
   376
StephaneLenclud@231
   377
                AttributeObjectProperty attribute = attributes[0];
StephaneLenclud@231
   378
StephaneLenclud@231
   379
                //Before anything we need to check if that kind of property is supported by our UI
StephaneLenclud@231
   380
                //Create the editor
StephaneLenclud@236
   381
                Control ctrl = CreateControlForProperty(pi, attribute, aObject);
StephaneLenclud@231
   382
                if (ctrl == null)
StephaneLenclud@231
   383
                {
StephaneLenclud@231
   384
                    //Property type not supported
StephaneLenclud@231
   385
                    continue;
StephaneLenclud@231
   386
                }
StephaneLenclud@231
   387
StephaneLenclud@231
   388
                //Add a new row
StephaneLenclud@231
   389
                iTableLayoutPanel.RowCount++;
StephaneLenclud@231
   390
                iTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
StephaneLenclud@231
   391
                //Create the label
StephaneLenclud@231
   392
                Label label = new Label();
StephaneLenclud@231
   393
                label.AutoSize = true;
StephaneLenclud@231
   394
                label.Dock = DockStyle.Fill;
StephaneLenclud@231
   395
                label.TextAlign = ContentAlignment.MiddleCenter;
StephaneLenclud@231
   396
                label.Text = attribute.Name;
StephaneLenclud@231
   397
                toolTip.SetToolTip(label, attribute.Description);
StephaneLenclud@231
   398
                iTableLayoutPanel.Controls.Add(label, 0, iTableLayoutPanel.RowCount-1);
StephaneLenclud@231
   399
StephaneLenclud@231
   400
                //Add our editor to our form
StephaneLenclud@231
   401
                iTableLayoutPanel.Controls.Add(ctrl, 1, iTableLayoutPanel.RowCount - 1);
StephaneLenclud@231
   402
                //Add tooltip to editor too
StephaneLenclud@231
   403
                toolTip.SetToolTip(ctrl, attribute.Description);
StephaneLenclud@231
   404
StephaneLenclud@231
   405
            }        
StephaneLenclud@231
   406
StephaneLenclud@231
   407
        }
StephaneLenclud@231
   408
StephaneLenclud@231
   409
        private void buttonTest_Click(object sender, EventArgs e)
StephaneLenclud@231
   410
        {
StephaneLenclud@231
   411
            FetchPropertiesValue(Object);
StephaneLenclud@231
   412
StephaneLenclud@231
   413
            //If our object has a test method with no parameters just run it then
StephaneLenclud@231
   414
            MethodInfo info = Object.GetType().GetMethod("Test");
StephaneLenclud@231
   415
            if ( info != null && info.GetParameters().Length==0)
StephaneLenclud@231
   416
            {
StephaneLenclud@231
   417
                info.Invoke(Object,null);
StephaneLenclud@231
   418
            }
StephaneLenclud@231
   419
StephaneLenclud@231
   420
        }
StephaneLenclud@231
   421
    }
StephaneLenclud@231
   422
}