예제 #1
0
 private void SetControlPropertyValue(Control oControl, string propName, object propValue)
 {
     try
     {
         if (oControl.InvokeRequired)
         {
             SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
             oControl.Invoke(d, new object[] { oControl, propName, propValue });
         }
         else
         {
             Type           t     = oControl.GetType();
             PropertyInfo[] props = t.GetProperties();
             foreach (PropertyInfo p in props)
             {
                 if (p.Name.ToUpper() == propName.ToUpper())
                 {
                     p.SetValue(oControl, propValue, null);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /***********************************************************************************************************/


        #region ------ Public Static Methods ------


        public static void SetControlValue(Control control, string argument, object value)
        {
            if (control.InvokeRequired)
            {
                SetControlValueCallback d = new SetControlValueCallback(SetControlValue);
                control.Invoke(d, new object[] { control, argument, value });
            }
            else
            {
                Type           type          = control.GetType();
                PropertyInfo[] propertyInfos = type.GetProperties();
                MethodInfo[]   methodInfos   = type.GetMethods();

                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    if (propertyInfo.Name.ToUpper() == argument.ToUpper())
                    {
                        propertyInfo.SetValue(control, value, null);
                    }
                }

                foreach (MethodInfo methodInfo in methodInfos)
                {
                    if (methodInfo.Name.ToUpper() == argument.ToUpper())
                    {
                        methodInfo.Invoke(control, new object[] { value + Environment.NewLine });
                    }
                }
            }
        }
예제 #3
0
 public void SetControlPropertyValue(Control control, string propertyName, object propertyValue)
 {
     try
     {
         if (control.InvokeRequired)
         {
             SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
             control.Invoke(d, new object[] { control, propertyName, propertyValue });
         }
         else
         {
             Type t = control.GetType();
             System.Reflection.PropertyInfo[] props = t.GetProperties();
             foreach (System.Reflection.PropertyInfo p in props)
             {
                 if (p.Name.ToUpper() == propertyName.ToUpper())
                 {
                     p.SetValue(control, propertyValue, null);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
예제 #4
0
 private static void RefreshPanel(Control pnlSort)
 {
     if (pnlSort.InvokeRequired)
     {
         var d = new SetControlValueCallback(RefreshPanel);
         pnlSort.Invoke(d, pnlSort);
     }
     else
     {
         pnlSort.Refresh();
     }
 }
예제 #5
0
 private void RefreshPanel(Control pnlSort)
 {
     if (pnlSort.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(RefreshPanel);
         pnlSort.Invoke(d, new object[] { pnlSort });
     }
     else
     {
         pnlSort.Refresh();
     }
 }
예제 #6
0
 //разблокирование кнопок после завершения всех процессов
 void SetControlPropertyValue(Button btn, string propName, object value)
 {
     if (btn.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
         btn.Invoke(d, new object[] { btn, propName, value });
     }
     else
     {
         btn.Enabled = true;
     }
 }
예제 #7
0
파일: Form1.cs 프로젝트: xwyangjshb/qizmt
 private void SetControlPropertyValue(Control oControl, string propName, object propValue)
 {
     if (oControl.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
         oControl.Invoke(d, new object[] { oControl, propName, propValue });
     }
     else
     {
         Type         t = oControl.GetType();
         PropertyInfo p = t.GetProperty(propName);
         p.SetValue(oControl, propValue, null);
     }
 }
예제 #8
0
 public void SetControlPropertyValue(Control oControl, string propName, object propValue)
 {
     if (oControl.InvokeRequired) {
         SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
         oControl.Invoke(d, new object[] { oControl, propName, propValue });
     } else {
         Type t = oControl.GetType();
         PropertyInfo[] props = t.GetProperties();
         foreach (PropertyInfo p in props) {
             if (p.Name.ToUpper() == propName.ToUpper()) {
                 p.SetValue(oControl, propValue, null);
             }
         }
     }
 }
예제 #9
0
파일: Form1.cs 프로젝트: xwyangjshb/qizmt
 private void AppendStatusText(Control oControl, string propName, object propValue)
 {
     if (oControl.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(AppendStatusText);
         oControl.Invoke(d, new object[] { oControl, propName, propValue });
     }
     else
     {
         Type         t        = oControl.GetType();
         PropertyInfo p        = t.GetProperty(propName);
         string       oldvalue = p.GetValue(oControl, null).ToString();
         if (oldvalue.Length > 0)
         {
             oldvalue += Environment.NewLine;
         }
         p.SetValue(oControl, oldvalue + propValue.ToString(), null);
     }
 }
예제 #10
0
 public void SetControlPropertyValue(Control p_oControl, string p_strPropName, object p_oPropValue)
 {
     if (p_oControl.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
         p_oControl.Invoke(d, new object[] { p_oControl, p_strPropName, p_oPropValue });
     }
     else
     {
         Type t = p_oControl.GetType();
         System.Reflection.PropertyInfo[] props = t.GetProperties();
         foreach (System.Reflection.PropertyInfo p in props)
         {
             if (p.Name.Trim().ToUpper() == p_strPropName.Trim().ToUpper())
             {
                 p.SetValue(p_oControl, p_oPropValue, null);
             }
         }
     }
 }
예제 #11
0
 private void SetControlPropertyValue(Control oControl, string propName, object propValue)
 {
     if (oControl.InvokeRequired)
     {
         SetControlValueCallback d = SetControlPropertyValue;
         oControl.Invoke(d, new object[] { oControl, propName, propValue });
     }
     else
     {
         Type           type  = oControl.GetType();
         PropertyInfo[] props = type.GetProperties();
         foreach (PropertyInfo p in props)
         {
             if (String.Equals(p.Name, propName, StringComparison.CurrentCultureIgnoreCase))
             {
                 p.SetValue(oControl, propValue, null);
             }
         }
     }
 }
예제 #12
0
        private void SetControlPropertyValue(Control control, string name, object value)
        {
            if (control.InvokeRequired)
            {
                SetControlValueCallback cb = new SetControlValueCallback(SetControlPropertyValue);
                control.Invoke(cb, new object[] { control, name, value });
            }
            else
            {
                Type           t     = control.GetType();
                PropertyInfo[] props = t.GetProperties();

                foreach (var p in props)
                {
                    if (p.Name.ToUpper() == name.ToUpper())
                    {
                        p.SetValue(control, value, null);
                    }
                }
            }
        }
예제 #13
0
        private void AlterLabelsInfo(Control oControl, string propName, object propValue)
        {
            if (oControl.InvokeRequired)
            {
                SetControlValueCallback d = new SetControlValueCallback(AlterLabelsInfo);
                oControl.Invoke(d, new object[] { oControl, propName, propValue });
            }
            else
            {
                Type           t     = oControl.GetType();
                PropertyInfo[] props = t.GetProperties();

                foreach (PropertyInfo p in props)
                {
                    if (p.Name.ToUpper() == propName.ToUpper())
                    {
                        p.SetValue(oControl, propValue, null);
                    }
                }
            }
        }
예제 #14
0
        //Um delegate é um elemento da linguagem C# que permite que você faça referência a um método.
        private void SetControlPropertyValue(Control oControl, string propName, object propValue) // controle entre tasks ou threads para cada permitir uma alteração por outra thread
        {                                                                                         // pode ser utilizado  para qualquer windows form basta modificar os controles
            SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);

            if (oControl.InvokeRequired)
            {
                oControl.Invoke(d, new object[] { oControl, propName, propValue });
            }
            else
            {
                Type           t     = oControl.GetType();
                PropertyInfo[] props = t.GetProperties();

                foreach (PropertyInfo p in props)
                {
                    if (p.Name.ToUpper() == propName.ToUpper())
                    {
                        p.SetValue(oControl, propValue, null);
                        break;
                    }
                }
            }
        }
예제 #15
0
        private void SetControlPropertyValue(Control oControl, string propName, object propValue)
        {
            // http://www.shabdar.org/cross-thread-operation-not-valid.html
            if (oControl.InvokeRequired)
            {
                SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
                oControl.Invoke(d, oControl, propName, propValue);
            }
            else
            {
                Type           t     = oControl.GetType();
                PropertyInfo[] props = t.GetProperties();
                foreach (PropertyInfo p in props)
                {
                    if (p.Name == propName)
                    {
                        p.SetValue(oControl, propValue, null);
                        return;
                    }
                }

                throw new ApplicationException(string.Format("Could not find property {0} in object {1}", propName, oControl));
            }
        }
        private static Action <TControlData> MakeControlSetterSafe <TControlData>(Control control, Action <TControlData> controlSetter)
        {
            var invokeSetControlData = new SetControlValueCallback <TControlData>(controlSetter);

            return(s =>
            {
                if (control.InvokeRequired)
                {
                    var findForm = control.FindForm();
                    if (findForm != null)
                    {
                        findForm.Invoke(invokeSetControlData, s);
                    }
                    else
                    {
                        throw new InvalidOperationException("This control is not attached to a winform.");
                    }
                }
                else
                {
                    controlSetter(s);
                }
            });
        }
예제 #17
0
파일: Form1.cs 프로젝트: erisonliang/qizmt
 private void AppendStatusText(Control oControl, string propName, object propValue)
 {
     if (oControl.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(AppendStatusText);
         oControl.Invoke(d, new object[] { oControl, propName, propValue });
     }
     else
     {
         Type t = oControl.GetType();
         PropertyInfo p = t.GetProperty(propName);
         string oldvalue = p.GetValue(oControl, null).ToString();
         if (oldvalue.Length > 0)
         {
             oldvalue += Environment.NewLine;
         }
         p.SetValue(oControl, oldvalue + propValue.ToString(), null);
     }
 }
예제 #18
0
파일: Form1.cs 프로젝트: erisonliang/qizmt
 private void SetControlPropertyValue(Control oControl, string propName, object propValue)
 {
     if (oControl.InvokeRequired)
     {
         SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
         oControl.Invoke(d, new object[] { oControl, propName, propValue });
     }
     else
     {
         Type t = oControl.GetType();
         PropertyInfo p = t.GetProperty(propName);                
         p.SetValue(oControl, propValue, null);                
     }
 }
예제 #19
0
        private void RefreshPanel(Control pictureBox)
        {
            ((PictureBox)pictureBox).Image = bitmap;
            if (pictureBox.InvokeRequired)
            {

                SetControlValueCallback d = new SetControlValueCallback(RefreshPanel);
                pictureBox.Invoke(d, new object[] { pictureBox });

            }
            else
            {

                pictureBox.Refresh();
            }
            //pictureBox.Update();
        }
예제 #20
0
파일: Form1.cs 프로젝트: nhatkycon/bxvinh
 public void SetControlPropertyValue(Control control, string propertyName, object propertyValue)
 {
     try
     {
         if (control.InvokeRequired)
         {
             SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
             control.Invoke(d, new object[] { control, propertyName, propertyValue });
         }
         else
         {
             Type t = control.GetType();
             System.Reflection.PropertyInfo[] props = t.GetProperties();
             foreach (System.Reflection.PropertyInfo p in props)
             {
                 if (p.Name.ToUpper() == propertyName.ToUpper())
                 {
                     p.SetValue(control, propertyValue, null);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }