winform 程序对界面上控件的统一控制【二】组件版
2010-02-10 15:38
471 查看
继上篇文章winform 程序对界面上控件的统一控制【一】(赋值\清空\验证……) ,本篇文章将实现一个同样功能的Component(组件)。
先看看组件的实现,如下所示:
代码三public partial class FrmChoose : Form
{
public FrmChoose()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="value"></param>
public FrmChoose(ITypeDescriptorContext context, List<RealSailing.UI.Utils.SetControl> value)
{
InitializeComponent();
this.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer | System.Windows.Forms.ControlStyles.UserPaint | System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
this.BackColor = System.Drawing.SystemColors.Control;
if (0 != value.Count)
{
control = value;
foreach (object c in context.Container.Components)
{
if (c.GetType().BaseType.Equals(typeof(RealSailing.DataSet.BaseDataSet)))
FillCombFiled(context, c);
}
}
else
{
RealSailing.UI.Utils.SetControl setControl;
foreach (object c in context.Container.Components)
{
if (arrType.Contains(c.GetType()))
{
setControl = new RealSailing.UI.Utils.SetControl
{
ControlName = c,
NullAble = false,
Default = null,
Formate = "",
KeyFiled = false,
FiledName = ""
};
control.Add(setControl);
}
else if (c.GetType().BaseType.Equals(typeof(RealSailing.DataSet.BaseDataSet)))
{
FillCombFiled(context, c);
}
}
}
this.gcSelect.DataSource = control;
}
/// <summary>
/// 用数据集中的列填充ComboBoxEdit控件
/// </summary>
/// <param name="context"></param>
/// <param name="c"></param>
private void FillCombFiled(ITypeDescriptorContext context, object c)
{
RealSailing.DataSet.BaseDataSet myDs = c as RealSailing.DataSet.BaseDataSet;
Type t = context.Instance.GetType();
System.Reflection.PropertyInfo p = t.GetProperty("DataMember");
object obj = p.GetValue(context.Instance, null);
string table = obj == null ? "" : obj.ToString();
if (myDs != null && !string.IsNullOrEmpty(table))
{
DataColumnCollection cols = myDs.Tables.Columns;
先看看组件的实现,如下所示:
代码三public partial class FrmChoose : Form
{
public FrmChoose()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="value"></param>
public FrmChoose(ITypeDescriptorContext context, List<RealSailing.UI.Utils.SetControl> value)
{
InitializeComponent();
this.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer | System.Windows.Forms.ControlStyles.UserPaint | System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
this.BackColor = System.Drawing.SystemColors.Control;
if (0 != value.Count)
{
control = value;
foreach (object c in context.Container.Components)
{
if (c.GetType().BaseType.Equals(typeof(RealSailing.DataSet.BaseDataSet)))
FillCombFiled(context, c);
}
}
else
{
RealSailing.UI.Utils.SetControl setControl;
foreach (object c in context.Container.Components)
{
if (arrType.Contains(c.GetType()))
{
setControl = new RealSailing.UI.Utils.SetControl
{
ControlName = c,
NullAble = false,
Default = null,
Formate = "",
KeyFiled = false,
FiledName = ""
};
control.Add(setControl);
}
else if (c.GetType().BaseType.Equals(typeof(RealSailing.DataSet.BaseDataSet)))
{
FillCombFiled(context, c);
}
}
}
this.gcSelect.DataSource = control;
}
/// <summary>
/// 用数据集中的列填充ComboBoxEdit控件
/// </summary>
/// <param name="context"></param>
/// <param name="c"></param>
private void FillCombFiled(ITypeDescriptorContext context, object c)
{
RealSailing.DataSet.BaseDataSet myDs = c as RealSailing.DataSet.BaseDataSet;
Type t = context.Instance.GetType();
System.Reflection.PropertyInfo p = t.GetProperty("DataMember");
object obj = p.GetValue(context.Instance, null);
string table = obj == null ? "" : obj.ToString();
if (myDs != null && !string.IsNullOrEmpty(table))
{
DataColumnCollection cols = myDs.Tables