本文整理汇总了C#中DataSource.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DataSource.GetType方法的具体用法?C# DataSource.GetType怎么用?C# DataSource.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSource
的用法示例。
在下文中一共展示了DataSource.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDataGridByDataSource
private Control CreateDataGridByDataSource(DataSource source)
{
var ret = new TableLayoutPanel();
ret.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
ret.RowCount = source.GetType().GetProperties().Count(p => p.CanWrite) + 1;
ret.ColumnCount = 2;
ret.AutoSize = true;
if (source is IOptional)
{
var title = new CheckBox() { Text = source.GetType().Name, TextAlign = ContentAlignment.MiddleCenter };
title.CheckedChanged += OnCheckChanged;
title.Checked = (source as IOptional).Enabled;
title.Font = new Font(title.Font, FontStyle.Bold);
ret.Controls.Add(title, 0, 0);
bindings[title] = source;
}
else
{
var title = new Label() { Text = source.GetType().Name, TextAlign = ContentAlignment.MiddleCenter };
title.Font = new Font(title.Font, FontStyle.Bold);
ret.Controls.Add(title, 0, 0);
}
var hideButton = new Button() { Text = "Hide", Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top };
hideButton.Click += OnButtonHideClick;
bindings[hideButton] = source;
bindings[ret] = source;
ret.Controls.Add(hideButton, 1, 0);
int propertyIndex = 1;
foreach (var prop in source.GetType().GetProperties())
{
if (!prop.CanWrite || Attribute.GetCustomAttribute(prop, typeof(HideInGui), true) != null)
continue;
ret.Controls.Add(new Label() { Text = prop.Name }, 0, propertyIndex);
var text = new TextBox();
text.Text = prop.GetValue(source, null).ToString();
text.Name = prop.Name;
if (source is IOptional)
text.Enabled = (source as IOptional).Enabled;
text.TextChanged += OnTextChange;
ret.Controls.Add(text, 1, propertyIndex);
bindings[text] = source;
propertyIndex++;
}
return ret;
}