[英]c# add text boxes together
I was wondering if there is a way to group 2 textboxes and 3 checkboxes together in c#. 我想知道是否有一种方法可以在C#中将2个文本框和3个复选框组合在一起。 I need to make 37 of these 5 boxes and I think making them manually in the design view would be inefficient.
我需要在这5个盒子中制作37个,我认为在设计视图中手动制作它们效率不高。 I'm not sure where to start I thought of making a class but I don't think it's possible to make a textbox a property of a class.
我不确定从哪里开始我想到要上课,但我认为不可能将文本框作为班级的属性。 The boxes also need to have different names so they don't conflict with each other.
这些框还需要使用不同的名称,以免彼此冲突。
After the suggestions I did end up using a user control. 在提出建议之后,我最终还是使用了用户控件。 Here is what I did to make 37 dynamic boxes
这是我制作37个动态盒子的过程
while (count < 36)
{
if (count >= 1)
{
if (count % 2 == 0)
{
x = 50;
y = y + 320;
}
else
{
x = 450;
}
}
if (count == 1)
{
y = 80;
}
var question = new Questions();
question.questions_Descriptionbox.Name = questionNames[count] + "_Descriptionbox";
question.questions_Descriptionbox.Text = question.questions_Descriptionbox.Name + count + " Y: " + y + " X:" + x + " Name:" + name;
question.questions_Descriptionbox.Location = new Point(x, y);
y = y + 70;
question.questions_checkboxok.Name = questionNames[count] + "_Okcheckbox";
question.questions_checkboxok.Text = question.questions_checkboxok.Name;
question.questions_checkboxok.Location = new Point(x, y);
x = x + 120;
question.questions_checkboxwarning.Name = questionNames[count] + "_Warningcheckbox";
question.questions_checkboxwarning.Text = question.questions_checkboxwarning.Name;
question.questions_checkboxwarning.Location = new Point(x, y);
x = question.questions_Descriptionbox.Location.X + 235;
question.questions_checkboxneedsattention.Name = questionNames[count] + "_NeedsAttentioncheckbox";
question.questions_checkboxneedsattention.Text = question.questions_checkboxneedsattention.Name;
question.questions_checkboxneedsattention.Location = new Point(x, y);
x = question.questions_Descriptionbox.Location.X;
y = y + 50;
question.questions_notebox.Name = questionNames[count] + "_Notecheckbox";
question.questions_notebox.Text = question.questions_notebox.Name;
question.questions_notebox.Location = new Point(x, y);
this.Controls.Add(question.questions_Descriptionbox);
this.Controls.Add(question.questions_checkboxok);
this.Controls.Add(question.questions_checkboxwarning);
this.Controls.Add(question.questions_checkboxneedsattention);
this.Controls.Add(question.questions_notebox);
count++;
}
the descriptionbox.text is just to verify that it is working the way it should. descriptionbox.text只是为了验证它是否可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.