我尝试添加更多的布尔值、文本框和组合框等组件。根据代码的底部。但布局很糟糕。我希望它以一种简洁的方式呈现给用户,以便用户快速轻松地更新值。因此,如果我可以指定每种类型应属于的位置,这将有所帮助。顶部的枚举,一堆下面的文本框等。
如何做到这一点?动态的,就像在表单设计器中一样。
所以想象一个用户控件矩形,如果我的道具列表有枚举、枚举、布尔值、布尔值、文本、整数、布尔值。我希望它以友好的方式显示,例如顶部的枚举、中间的文本框、布尔值。等等
private void updateIcons(List<Props> prop) {
countControls++;
locationY = 10;
int gbHeight;
foreach (var p in prop) {
radioButtonY = 10;
IType pType = p.Type;
if (pType is Enum) {
var myP = new MyProp(p, this);
GroupBox gb = new GroupBox();
gb.Location = new Point(nextLocationX,locationY);
nextLocationX += rbWidth+10;
gb.Name = "groupBox" + countControls;
gb.Text = "smthn";
var TypesArray = set here;
gbHeight = TypesArray.Length;
foreach (var type in TypesArray) {
getimagesPath(TypesArray);
RadioButton rb = new RadioButton();
rb.Appearance = Appearance.Button;
rb.Width = rbWidth;
rb.Height = rbHeight;
rb.Name = type.Name + countControls;
rb.Text = type.Name;
string path = imagePaths[type.Name];
Bitmap rbImage = new Bitmap(path);
rb.BackgroundImage = rbImage;
countControls++;
rb.Location = new Point(radioButtonX, radioButtonY);
if (myP.Value != null && type.Name.SafeEquals(myP.Value.ToString())) {
rb.Checked = true;
}
radioButtonY += rbHeight;
gb.Controls.Add(rb);
rb.CheckedChanged += rb_CheckedChanged;
}
gb.Height = rbHeight * gbHeight + 20;
gb.Width = rbWidth + 10;
Controls.Add(gb);
}
}
}
if(pType is string){
TextBox tb = new TextBox();
tb.Text = pType.ToString();
}