Example #1
0
        void setControlPropertyValue(Control control, object value, string property_name = "Text", bool update = true)
        {
            if (control.InvokeRequired)
            {
                setControlPropertyValueCallback d = new setControlPropertyValueCallback(setControlPropertyValue);
                this.Invoke(d, new object[] { control, value, property_name, update });
            }
            else
            {
                var property = control.GetType().GetProperty(property_name);
                if (property != null)
                {
                    property.SetValue(control, value);
                }

                if (update)
                {
                    var method = control.GetType().GetMethod("Update");
                    if (method != null)
                    {
                        method.Invoke(control, null);
                    }
                }
            }
        }
/*
 *      void updateSerialPorts()
 *      {
 *          if (comboBox_serialPorts.InvokeRequired)
 *          {
 *              updateSerialPortsCallback d = new updateSerialPortsCallback(updateSerialPorts);
 *              this.Invoke(d, new object[] { });
 *          }
 *          else
 *          {
 *              comboBox_serialPorts.DataSource = SerialPort.GetPortNames();
 *              comboBox_serialPorts.Refresh();
 *          }
 *      }
 */
        void controlSetProperty(Control control, object value, string property_name = "Text")
        {
            if (control.InvokeRequired)
            {
                setControlPropertyValueCallback d = new setControlPropertyValueCallback(controlSetProperty);
                this.Invoke(d, new object[] { control, value, property_name });
            }
            else
            {
                var property = control.GetType().GetProperty(property_name);
                if (property != null)
                {
                    property.SetValue(control, value);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Sets the text property of any control as long as it has one
 /// </summary>
 /// <param name="control"></param>
 /// <param name="value"></param>
 void controlSetText(Control control, object value, string property_name = "Text")
 {
     if (control.InvokeRequired)
     {
         setControlPropertyValueCallback d = new setControlPropertyValueCallback(controlSetText);
         this.Invoke(d, new object[] { control, value, property_name });
     }
     else
     {
         var property = control.GetType().GetProperty(property_name);
         if (property != null)
         {
             property.SetValue(control, value);
         }
     }
 }