【发布时间】:2013-05-24 12:40:42
【问题描述】:
我尝试添加更多的布尔值、文本框和组合框等组件。根据代码的底部。但布局很糟糕。我希望它以一种简洁的方式呈现给用户,以便用户快速轻松地更新值。因此,如果我可以指定每种类型应属于的位置,这将有所帮助。顶部是枚举,下面是一堆文本框,等等。
如何做到这一点?动态的,就像在表单设计器中一样。
想象一个用户控件矩形,如果我的道具列表有 enum,enum,bool,bool,text,int,bool。我希望它以友好的方式显示,例如顶部的枚举、中间的文本框、布尔值。等等。
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();
}
【问题讨论】:
-
您的问题到底是什么?你不喜欢你的布局结果如何?您的问题非常含糊不清,我真的不知道您到底在寻找什么。
-
试图解释,因为我的名声不能发布图片。
-
所以想象一个用户控件矩形,如果我的道具列表有 enum,enum,bool,bool,text,int,bool。我希望它以友好的方式显示,例如顶部的枚举、中间的文本框、布尔值。等
-
好的,你还是没有问题。将您的图片发布到 imgur.com 并将其添加为链接。
-
只需将控件添加到具有垂直方向的 FlowLayoutPanel。
标签: c# .net winforms user-interface