} 有人可以帮我吗…… 谢谢 Vinay 解决方案 Vinay,您可以在设计时&在rutime时,您会为每个命令加载该表单的新实例.要尝试的是,只需在解决方案中添加一个表单即可(不添加任何代码).默认情况下,它将称为Form1.然后,使用以下代码: foreach (字符串 COMPORTNAME in 中.GetPortNames()){ span> Form1 frm = 新 Form1(); span> frm.Text = COMPORTNAME; span> frm.Show(); } 跨度>这将为每个命令打开一个表单1的实例,并将表单的标题设置为命令的名称.希望这会有所帮助, Hi...I want to add Forms dynamically...i'm developing an application which gets names of COM ports present on a PC. So for each COM port i want one seperate form & i want to do this dynamically.For getting COM present on my PC i am using this line...now in this i want to create seperate forms for each COM port with the names same as COM port names. In this i am getting all my comports names in the variable COMPORTNAME so with the same name i've to create a Formforeach (string COMPORTNAME in SerialPort.GetPortNames()){//Here form should get created dynamically when i run my application} can anybody help me in this... Thanks,Vinay 解决方案 Hi Vinay,You can create one form in designtime & at rutime you load an new instance of that form for each comport.To try is, just add a form to your solution (don't add any code). It will be called Form1 by default. Then, use the following code: foreach (string COMPORTNAME in SerialPort.GetPortNames()) { Form1 frm = new Form1(); frm.Text = COMPORTNAME; frm.Show(); }This will open one instance of form one for each comport and set the caption of the form to the name of the comport.Hope this helps, 这篇关于如何动态添加表单...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-26 02:51