我在Windows窗体中有一个下拉列表,面板和一个按钮控件 下拉列表项将为1,2,3. 因此,当我从下拉列表中选择任何值时,我希望创建一个带有文本框的面板,并根据下拉列表中的项目值将动态创建的面板添加到已经存在的面板中 即,如果我选择2,则应在主面板中添加两个面板. 有人可以帮我吗? ***默认情况下,一个面板在主面板中是静态的.因此,当我给出2时,它应该有2个面板,其中包括一个已经存在的面板. 预先表示感谢.
Hi, I have a dropdown list,panel and a button control in a windows form The dropdown list items will be 1,2,3. So when i select any of the value from dropdown list i want a panel with textbox to be created and add the dynamically created panel to the already existing panel based on the items value in dropdown i.e., if i select 2 ,then two panels should be added to the main panel. Can anybody help me out of this. *** Default one panel will be static in the main panel.So when i give 2 it should have 2 panels including the one which is already present. Thanks in advance.
推荐答案只需创建它们,并将它们添加到现有的Panel.Controls列表中: Just create them, and add them to the existing Panel.Controls list: Panel p1 = new Panel(); Panel p2 = new Panel(); myPanelInMainForm.Controls.Add(p1); myPanelInMainForm.Controls.Add(p2);
您可能想要设置大小和位置,但这很简单……
You will probably want to set the size, and location, but that''s trivial...
我认为OriginalGriff"答案是完整的,但只想添加一点点转折.由于您正在使用Forms,您是否注意到..Designer.cs中有一些生成的代码?看一看该代码,您会注意到Visual Studio实际上是如何在窗体上添加控件的.您也可以在代码中使用相同的原则:) I think OriginalGriff''s answer is complete but just want to add a little twist. Since you''re working with Forms have you noticed that you have some generated code in the ..Designer.cs? Have a look at that code and you''ll notice how Visual Studio actually adds the controls on your forms. You can use the same principles in your code also :)
更多推荐
将动态面板添加到Windows窗体中已存在的面板中
发布评论