将动态面板添加到Windows窗体中已存在的面板中

编程入门 行业动态 更新时间:2024-10-23 00:23:59
本文介绍了将动态面板添加到Windows窗体中已存在的面板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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窗体中已存在的面板中

本文发布于:2023-11-06 13:41:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563847.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:面板   窗体   动态   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!