You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/AutoControl/ControlsHelper.cs

44 lines
1.5 KiB
C#

using Mesnac.Action.ChemicalWeighing.AutoControl.Entity;
using Mesnac.Controls.Base;
using Mesnac.Controls.ChemicalWeighing;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.AutoControl
{
public class ControlsHelper
{
/// <summary>
/// 控件导入
/// </summary>
public static void ControlImport(MCTextBoxEntity textE, ButtonEntity buttonE,
MCComboBoxEntity comboE, MCLabelEntity labelE, MCRadioButtonEntity radioE,
List<Control> McControls)
{
FillBase<MCTextBox>(textE, McControls);
FillBase<System.Windows.Forms.Button>(buttonE, McControls);
FillBase<MCCombobox>(comboE, McControls);
FillBase<MCLabel>(labelE, McControls);
FillBase<MCRadioButton>(radioE, McControls);
}
private static void FillBase<T>(object E, List<Control> McControls) where T : class
{
PropertyInfo[] sourcePropertyInfoList = E.GetType().GetProperties();
foreach (PropertyInfo sourceProperty in sourcePropertyInfoList)
{
string name = sourceProperty.Name;
var pro = McControls.FirstOrDefault(x => x.Name == name) as T;
sourceProperty.SetValue(E, pro);
}
}
}
}