【发布时间】:2018-10-19 13:03:41
【问题描述】:
所以我的问题是我想通过单击按钮将组合框添加到基于 Windows 窗体的程序中。我现在拥有的是:
private void addCoworkerBox()
{
DDLList.Add(new ComboBox());
comboBoxInit(coworkerIndex);
coworkerIndex++;
}
和:
private void comboBoxInit(int i)
{
var yValue = DDLCoworker.Location.Y;
DDLList[i].DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
DDLList[i].Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
DDLList[i].FormattingEnabled = true;
yValue += 34;
DDLList[i].Location = new System.Drawing.Point(380, yValue);
DDLList[i].Name = "comboBox";
DDLList[i].Size = new System.Drawing.Size(121, 28);
DDLList[i].TabIndex = 2;
DDLList[i].Items.AddRange(names.ToArray());
DDLList[i].Show();
}
列表 DLLList、int yValue 和 int coworkerindex 在我的代码中进一步初始化。
我知道这是一种转发,但其他人的答案似乎对我没有帮助。
上面的代码不起作用。当我按下应该添加新组合框的按钮时,没有任何反应。我为该按钮添加了一个函数,它调用addCoworkerBox() 函数。
【问题讨论】:
-
那么你的问题是什么?此代码是否无法按您希望的方式工作?为什么不呢?
-
“当我按下按钮时”哪个按钮?新创建的
ComboBox中的那个? -
@stuartd 哦,抱歉我的问题不清楚。我只是将它编辑到我的问题的最后一部分指定我的代码不起作用的地方。
-
@MindSwipe 对你来说,很抱歉不清楚。刚刚在我的帖子中澄清了!我说的是调用函数
addCoworkerBox()的按钮